groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Søren Berg Glasius <>
Subject Re: non-catchable exception?
Date Wed, 12 Oct 2016 16:27:10 GMT
This question should be asked in

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: <> <>
Reply: <> <>
Date: 12. oktober 2016 at 18.24.20
To: <> <>
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 {
} catch (exception) {
println "bar caught $exception"
static main(args) {
try {
} 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.


View raw message