catch doesn't catch a thrown exception

Discussion in 'Java' started by Marteno Rodia, Aug 3, 2009.

  1. 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?

    Marteno Rodia, Aug 3, 2009
    1. Advertisements

  2. Marteno Rodia

    markspace Guest

    Beats me, it should work, I've done it.

    SSCCE please.
    markspace, Aug 3, 2009
    1. Advertisements

  3. do you catch(Exception) or catch(Error) or...? Error does not extend
    Exception (

    Alessio Stalla, Aug 3, 2009
  4. Marteno Rodia

    Roedy Green Guest

    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.
    Roedy Green Canadian Mind Products

    "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)
    Roedy Green, Aug 3, 2009
  5. 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 :)
    Marcin Rodzik, Aug 4, 2009
  6. Marteno Rodia

    Daniel Pitts Guest

    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.
    Daniel Pitts, Aug 5, 2009
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.