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?

    MR
    Marteno Rodia, Aug 3, 2009
    #1
    1. Advertising

  2. Marteno Rodia

    markspace Guest

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


    Marteno Rodia wrote:

    > 3) is there any other explanation?



    SSCCE please.
    markspace, Aug 3, 2009
    #2
    1. Advertising

  3. On Aug 3, 1:09 pm, Marteno Rodia <> wrote:
    > 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
    Alessio Stalla, Aug 3, 2009
    #3
  4. Marteno Rodia

    Roedy Green Guest

    On Mon, 3 Aug 2009 04:09:27 -0700 (PDT), Marteno Rodia
    <> wrote, quoted or indirectly quoted someone who
    said :

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

    Daniel Pitts Guest

    Marcin Rodzik wrote:
    > 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.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Aug 5, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Selen
    Replies:
    0
    Views:
    2,673
    Selen
    May 28, 2004
  2. =?Utf-8?B?VmFs?=
    Replies:
    0
    Views:
    3,120
    =?Utf-8?B?VmFs?=
    Jun 8, 2005
  3. Fao, Sean
    Replies:
    5
    Views:
    394
    Fao, Sean
    Jul 6, 2003
  4. drop
    Replies:
    0
    Views:
    387
  5. Replies:
    1
    Views:
    614
    Ivan Vecerina
    May 15, 2006
Loading...

Share This Page