Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:44:07+00:00 2026-06-17T09:44:07+00:00

This is a simple question that I cant just figure out: The following code

  • 0

This is a simple question that I cant just figure out:

The following code gives the following compilation error:

def parseJson(q: String) = Option[JsValue]{
    try{
            Json.parse(q)
    }catch{
        case e: com.codahale.jerkson.ParsingException => None
    }
}

Error

[error]  found   : None.type (with underlying type object None)
[error]  required: play.api.libs.json.JsValue
[error]             case e: com.codahale.jerkson.ParsingException => None

Why cant I return None considering my response type is Option[JsValue]?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:44:08+00:00Added an answer on June 17, 2026 at 9:44 am

    You actually want to put Json.parse(q) into Some() and not wrapping the whole code in an Option[JsValue], but using it as signature:

    def parseJson(q: String): Option[JsValue] = {
        try{
           Some(Json.parse(q))
        }catch{
           case e: com.codahale.jerkson.ParsingException => None
        }
    }
    

    But anyway, you should prefer using scala.util.control.Exception:

     import scala.util.control.Exception._
     catching(classOf[com.codahale.jerkson.ParsingException]).opt(Json.parse(q))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem like a simple question, bu tI just can't figure out what
This is a simple question that I just can't seem to get figured out
This is a super simple question that I just can't seem to find a
This is probably a very simple question but I just can't seem to figure
This is admittedly a very simple question that I just can't find an answer
This should be a simple question, but I can't seem to figure it out.
I'm positive this is a simple question, but I can't figure it out. I'm
Just starting to figure Python out. I've read this question and its responses: Is
This is quite a simple question - although one that is on my mind
This is a simple question which makes it painfully obvious that I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.