Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

As a java programmer, I have always been critical of Unchecked Exceptions. Mostly programmers use it as an en-route to coding easiness only to create trouble later. Also the programs (though untidy) with checked exceptions are much robust compared to unchecked counterparts.

Surprisingly in Scala, there is nothing called Checked Exceptions. All the Java checked and unchecked are unchecked in Scala.

What is the motivation behind this decision? For me it opens wide range of problems when using any external code. And if by chance the documentation is poor, it results in KILL.

share|improve this question
As a Java programmer, I have always been critical of checked exceptions. Untidy code is never robust. –  Michael Borgwardt Nov 30 '12 at 8:11

2 Answers 2

up vote 14 down vote accepted

Checked exceptions are mostly considered a failure. Note that no languages created after Java adopted them. See http://www.artima.com/intv/handcuffs2.html, http://googletesting.blogspot.ru/2009/09/checked-exceptions-i-love-you-but-you.html, http://www.mindview.net/Etc/Discussions/CheckedExceptions, etc.

In particular, they are uncomposable (except by reverting to throws Exception).

In Scala you have a better option: using algebraic types for return values such as Option[T], Either[Exception, T], your own type when you want the user to handle specific cases (e.g. instead of

def foo: Int // throws FileNotFoundException, IllegalStateException

you have

sealed trait FooResult
case class Success(value: Int) extends FooResult
case class FileNotFound(file: File) extends FooResult
case object IllegalState extends FooResult

def foo: FooResult

and the consumer now is required to handle all results)

For dealing with external code which does throw exceptions, you have scala.util.control.exception or scala.util.Try (starting with Scala 2.10).

share|improve this answer
Never understood the most people don't handle checked exceptions` argument. Most people aren't good developers. I guarantee that most developers aren't going to handle error result anyway. Actually, try..catch seems much more readable than if. What's more I can also guarantee that those same most developers aren't going to write code that returns error result - too complicated in Scala - you can't even return from a function whenever you want (just like in Pascal) –  Pius Oct 26 '14 at 6:19
I find you comment confusing and lacking in evidence, @Pius. In Scala, choosing Option as the return type is likely to result in pattern matching rather than If statements. Returning None rather than Some in that style is trivial, not complex. Less clueful developers might not choose to write functions which return algebraic types but that is a different thing. Finally, ¨you can´t even return from a function whenever you want¨ - simply untrue. –  itsbruce Dec 9 '14 at 14:38

If you want to gain efficiency, you have to give up.. precision/control <-- I need a better word for that.

Scala is located towards the top as far as abstraction goes. If one of Scala's goals is getting rid of annoying boilerplate code, then an obvious place to look at is Java's exception handling. If you want to write fast code in java, just keep throwing your checked exceptions up until they hit main() and effectively become unchecked.

I don't know if I'm getting at exactly what you're asking but this is the most obvious reason in my opinion.

Well, I did a little looking and someone has written about the tragedy of check exceptions.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.