In Scala, is there a pre-existing library function for converting exceptions to Options?

前端 未结 5 1404
心在旅途
心在旅途 2021-02-05 06:32

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:

5条回答
  •  长发绾君心
    2021-02-05 06:45

    Yes, you can take a look to the scala.util.control.Exception object. Especially, the allCatch function.

提交回复
热议问题