Initialising vals which might throw an exception
- by Paul Butcher
I need to initialise a set of vals, where the code to initialise them might throw an exception. I'd love to write:
try {
val x = ... generate x value ...
val y = ... generate y value ...
} catch { ... exception handling ... }
... use x and y ...
But this (obviously) doesn't work because x and y aren't in scope outside of the try.
It's easy…