What does Scala’s “try” mean without either a catch or finally block?

Scala’s exception handling works by passing any exceptions to an anonymous catch function. The catch function works by pattern matching the caught exception and, if it doesn’t match it will pass the exception up.

The catch function is optional, if it’s omitted then the exception is passed straight up. So essentially

try { exceptionThrowingFunction() }

is the same as

exceptionThrowingFunction()

See chapter 6.22 of the language spec pdf for more information.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)