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

  • Home
  • SEARCH
  • 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 6782013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:41:28+00:00 2026-05-26T16:41:28+00:00

This is basically to wrap java factory methods which throw exceptions if the item

  • 0

This is basically to wrap java factory methods which throw exceptions if the item can’t be created based on the inputs. I’m looking for something in the base library like:

 def exceptionToOption[A](f: => A):Option[A] ={
    try{
      Some(f)}
    catch{
      case e:Exception => None}
  }

Usage:

val id:Option[UUID] = exceptionToOption(UUID.fromString("this will produce None"))

I know I can write my own but I want to check I am not re-inventing the wheel.

  • 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-05-26T16:41:29+00:00Added an answer on May 26, 2026 at 4:41 pm

    Use scala.util.control.Exception:

    import scala.util.control.Exception._
    
    allCatch opt f
    

    And you can make it more sophisticated. For example, to catch only arithmetic exceptions and retrieve the exception:

    scala> catching(classOf[ArithmeticException]) either (2 / 0)
    res5: Either[Throwable,Int] = Left(java.lang.ArithmeticException: / by zero)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code basically translates characters based on position in one string to the character
I'm using a framework called Processing which is basically a Java applet. It has
I'm trying to wrap my head around this in LINQPAD and keep failing. Basically
I really can't wrap my mind around this: Previously I couldn't get Framebuffers to
I have several methods that I need to wrap in new methods in basically
So, I have this nice little view that I've made, which basically shows two
Is there any way you can make IntelliJ wrap scaladoc at the margin? Basically,
I found this thread which basically has the same issue I have. But their
I'm trying to wrap my head around this. My language is Java using PlayFramework
Im trying do this basically: var tr = document.createElement(tr); var td = document.createElement(td); td.appendChild(document.createTextNode('<input

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.