3

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 ?

blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • Possible duplicate of [How does scala generated byte code drops the checked exception?](http://stackoverflow.com/questions/4337281/how-does-scala-generated-byte-code-drops-the-checked-exception) – badcook Feb 17 '16 at 13:44

1 Answers1

6

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.

Community
  • 1
  • 1
badcook
  • 3,699
  • 14
  • 25