chbrown
chbrown

Reputation: 12028

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.

Upvotes: 4

Views: 356

Answers (1)

Chris Martin
Chris Martin

Reputation: 30736

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

Upvotes: 2

Related Questions