Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning about possible thrown exceptions in Scala

Scala usually (apart from intrinsically error-prone things like I/O) keeps me from inadvertently shooting myself in the foot by virtue of its type checking system. But there are some features (which I sometimes need), like Map#apply(), or List#head that may throw errors.

Is there a way to tell the Scala compiler to warn me when I call something that may throw?

I realize these warnings might turn into a deluge as you go down the JVM rabbit hole, so I expect I'd need to filter out OutOfMemoryError and its kin, but I'm okay with that. Scala, as a platform, seems to be very much about safety, so I figure I'm just missing something simple — but Googling around for Scala warning options left me with only the -unchecked, -deprecation, and -feature flags, all of which I'm already using.

like image 638
chbrown Avatar asked Oct 22 '25 02:10

chbrown


1 Answers

WartRemover can give you warnings for some of the more common problems with partial functions in the Scala core library.

like image 197
Chris Martin Avatar answered Oct 24 '25 21:10

Chris Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!