This question should be asked in [email protected]
And the answer to the question must be, no. But you could check if
} catch (exception) {
if(exception instance MySpecialException) throw exception
println "bar caught $exception"
}
Best regards,
Søren Berg Glasius
Hedevej 1, Gl. Rye, 8680 Ry, Denmark
Mobile: +45 40 44 91 88, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.
From: [email protected] <[email protected]> <[email protected]>
Reply: [email protected] <[email protected]> <[email protected]>
Date: 12. oktober 2016 at 18.24.20
To: [email protected] <[email protected]> <[email protected]>
Subject: non-catchable exception?
Hello there,
is it possible to create an exception which will *not* be caught by a
general handler, only by a specific one? So that e.g., the following code
===
class MySpecialException extends Exception { /* whatever magic needed here
*/ }
...
def foo() {
throw new MySpecialException()
}
def bar() {
try {
foo()
} catch (exception) {
println "bar caught $exception"
}
}
static main(args) {
try {
bar()
} catch (MySpecialException special) {
println "special exception"
}
}
===
would print out "special exception" and *not* "bar caught..."?
The reason is that the code I at the moment work with contains _lots_ of
generic try/catch harnesses at different levels of code; they generally
report the error caught and then go on processing the input. Now I would
need a „special” exception which would not be caught by any of them, to
abort the processing immediately.
Adding a separate "catch (MySpecialException goup) { throw goup }"
statement to each of all those already existing harnesses -- which would
be, I guess, conceptually the right thing to do -- would be rather at the
inconvenient side.
Thanks,
OC