Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Scala ignore Java's checked exceptions?

Tags:

scala

For example if invoke Java Thread.sleep which throws a checked InterruptedException from a Scala source file then not required to surround the call in a Scala try catch. How is Scala removing the rule to surround the call in a try catch ?

like image 308
blue-sky Avatar asked Oct 14 '25 09:10

blue-sky


1 Answers

The short answer is that Scala compiles straight down to JVM bytecode, not through Java. Therefore it is only beholden to JVM bytecode rules, not Java ones (and indeed Scala omits checked exceptions altogether), although for purposes of interoperability it might preserve many Java concepts.

As for why the generated bytecode can skip the original checked exceptions, see this question.

like image 175
badcook Avatar answered Oct 16 '25 23:10

badcook



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!