Catching unknown exceptions

Discussion in 'C++' started by Bryan, Sep 24, 2005.

  1. Bryan

    Bryan Guest

    I have an unknown error in some legacy code. I can catch it with catch
    (...), but I cannot tell what kind of error it is.

    Is there any base exception class (like in java) that I can try and
    catch that might give me some more meaningful information? Or
    suggestions on the most common exceptions so I can just try them?

    Thanks,
    Bryan
    Bryan, Sep 24, 2005
    #1
    1. Advertising

  2. Bryan

    Ian Guest

    Bryan wrote:
    > I have an unknown error in some legacy code. I can catch it with catch
    > (...), but I cannot tell what kind of error it is.
    >
    > Is there any base exception class (like in java) that I can try and
    > catch that might give me some more meaningful information? Or
    > suggestions on the most common exceptions so I can just try them?
    >

    std::exception

    Ian
    Ian, Sep 24, 2005
    #2
    1. Advertising

  3. Bryan

    benben Guest

    > std::exception

    Not necessarily!

    A short answer to OP's question is: "There's no way you can do that".

    A slightly longer answer is, if you don't know what exception is being
    thrown after consulting all documentation, then it is better to:
    - not catching the exception at all, or
    - catch it but not to deal with the object being thrown.

    Of course, if you are debugging, that's a different story. Your development
    tools should have some function to pierce into the exception object
    internals.

    Ben
    benben, Sep 24, 2005
    #3
  4. Bryan

    Greg Guest

    Bryan wrote:
    > I have an unknown error in some legacy code. I can catch it with catch
    > (...), but I cannot tell what kind of error it is.
    >
    > Is there any base exception class (like in java) that I can try and
    > catch that might give me some more meaningful information? Or
    > suggestions on the most common exceptions so I can just try them?
    >
    > Thanks,
    > Bryan


    The ellipsis indicates that the catch clause doesn't care what kind of
    exception it has caught. Its purpose is to to catch every exception. By
    the time this catch clause executes, it's too late to wonder what kind
    of exception was thrown. Because if the thrown type really were of
    interest, it should have already been caught.

    Generally, when the type of a thrown exception can vary, a C++ program
    will declare a series of catch clauses with the ellipsis catch-all
    coming last:

    catch (std::exception& InException)
    {
    ...
    }

    catch (int inOSErr)
    {
    ...
    }

    catch (...) // for thrown types not already caught
    {
    ...
    }

    Greg
    Greg, Sep 24, 2005
    #4
    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. Marina
    Replies:
    2
    Views:
    467
    Marina
    Jul 8, 2003
  2. Amil Hanish
    Replies:
    0
    Views:
    539
    Amil Hanish
    Apr 13, 2006
  3. Adam Maass
    Replies:
    5
    Views:
    395
    Sudsy
    Jul 22, 2003
  4. Harlin Seritt

    Catching an unknown error

    Harlin Seritt, Mar 23, 2007, in forum: Python
    Replies:
    7
    Views:
    286
    Harlin Seritt
    Mar 23, 2007
  5. Vincent Arnoux
    Replies:
    1
    Views:
    234
    Arnaud Bergeron
    Aug 11, 2006
Loading...

Share This Page