catch doesn't catch a thrown exception

M

Marteno Rodia

Of course, I don't think it is ever possible, but let me begin from
the start...

I'm using in my program a method delivered to me (let's call it the
"super method") and it uses a few methods from its native packet (a
pretty long list of nested invocations). In some cases, an error
occurs and one of the methods invoked throws a new Error("message")
(not an Exception, but an Error).

I just happen to want to handle this error (it's a little strange,
however, desired in this case), but I encountered quite a big problem:
the try-catch I've put the "super method" in exits normally, without
going into the catch section...

I'm really confused, and I can see only 2 explanations:
1) There is another catch (on a different level of the call stack)
which I didn't notice and the error is handled silently there.
2) There is something I don't know about unchecked exceptions like my
Error class.

1') how to check where the exception/error is really handled? (I've
been looking into the code for hours...)
2') what is that I don't know?
3) is there any other explanation?

MR
 
A

Alessio Stalla

Of course, I don't think it is ever possible, but let me begin from
the start...

I'm using in my program a method delivered to me (let's call it the
"super method") and it uses a few methods from its native packet (a
pretty long list of nested invocations). In some cases, an error
occurs and one of the methods invoked throws a new Error("message")
(not an Exception, but an Error).

I just happen to want to handle this error (it's a little strange,
however, desired in this case), but I encountered quite a big problem:
the try-catch I've put the "super method" in exits normally, without
going into the catch section...

I'm really confused, and I can see only 2 explanations:
1) There is another catch (on a different level of the call stack)
which I didn't notice and the error is handled silently there.
2) There is something I don't know about unchecked exceptions like my
Error class.

1') how to check where the exception/error is really handled? (I've
been looking into the code for hours...)
2') what is that I don't know?
3) is there any other explanation?

do you catch(Exception) or catch(Error) or...? Error does not extend
Exception (http://java.sun.com/javase/6/docs/api/java/lang/
Error.html).

AS
 
R

Roedy Green

Of course, I don't think it is ever possible, but let me begin from
the start...

I saw a documentary about medicine in ancient China. Women were so
modest they could not disrobe or even talk about their medical
conditions. The best they could do was point at a doll.

You need to post some code to make your complaint clear.
see http://mindprod.com/jgloss/sscce.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Patriotism is fierce as a fever, pitiless as the grave, blind as a stone, and as irrational as a headless hen."
~ Ambrose Bierce (born: 1842-06-24 died: 1914 at age: 71)
 
M

Marcin Rodzik

The Error is thrown, and I try to catch Throwable, so it should be OK.

The code is so enormous that it's no use posting it. If I had chosen
only "important" part, I would have probably omitted the problem,
because the problem was I didn't know where the problem was. The
application contains a few threads, that was the reason I was not sure
how to use debugger. Anyway, I tried to track execution of the
problematic part of the code, and I saw that there is another try-
catch I haven't notice (I'm sure I wouldn't have posted it!)

It is obvious that caught exception is no longer thrown, so the
problem disappeared :)

Anyway, thank to everyone who longed to help me :)
MR
 
D

Daniel Pitts

Marcin said:
The Error is thrown, and I try to catch Throwable, so it should be OK.

The code is so enormous that it's no use posting it. If I had chosen
only "important" part, I would have probably omitted the problem,
because the problem was I didn't know where the problem was. The
application contains a few threads, that was the reason I was not sure
how to use debugger. Anyway, I tried to track execution of the
problematic part of the code, and I saw that there is another try-
catch I haven't notice (I'm sure I wouldn't have posted it!)

It is obvious that caught exception is no longer thrown, so the
problem disappeared :)

Anyway, thank to everyone who longed to help me :)
MR
That is one of the benefits of attempting to construct an SSCCE. If you
can't construct it from the bits of the program you think are causing
the problem, then its actually being caused in the bits you *aren't*
thinking about.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top