how to catch uncaught exception

Discussion in 'C++' started by nrhayyal, Jun 9, 2005.

  1. nrhayyal

    nrhayyal Guest

    hi all,
    i am facing a problem in catching an exception which is uncaught in any
    of the catch block.
    not doing so will gives me coredump.
    I tried by rewriting set_unexpected() and set_terminate() function.
    But these works fine only for small programs.
    when i tried with my large applications which links to n num of
    different libraries, it doesnot work.
    so please help me to handle uncaught exception on any of the UNIX
    flavors(it will be more helpful ,if it is AIX5.2).
    please help me ASAP.
    Thanks in advance.

    Thanks & Regards
    Nagaraj Hayyal
     
    nrhayyal, Jun 9, 2005
    #1
    1. Advertising

  2. nrhayyal

    msalters Guest

    nrhayyal schreef:
    > hi all,
    > i am facing a problem in catching an exception which is uncaught in any
    > of the catch block.


    catch(...) will catch any C++ exception. You can't access the caught
    object, though - for that you need the type.

    You cannot catch a CPU exception, but that would of course be off-topic
    here. C++ doesn't deal with those.

    HTH,
    Michiel Salters
     
    msalters, Jun 9, 2005
    #2
    1. Advertising

  3. nrhayyal

    Me Guest

    > i am facing a problem in catching an exception which is uncaught in any
    > of the catch block.
    > not doing so will gives me coredump.
    > I tried by rewriting set_unexpected() and set_terminate() function.
    > But these works fine only for small programs.
    > when i tried with my large applications which links to n num of
    > different libraries, it doesnot work.
    > so please help me to handle uncaught exception on any of the UNIX
    > flavors(it will be more helpful ,if it is AIX5.2).


    Riiiight. Why don't you find out what is throwing the exception in your
    callstack and either fix it not to throw the exception (and by that I
    don't mean removing the throw statement) or handle it by catching the
    type explicitly. This program is behaving exactly like it was designed
    to do and I highly suggest you do not hack around it by playing with
    set_unexpected/set_terminate/catch(...) or it will be even more
    difficult to fix and debug. So what you need to do is figure out how to
    get a callstack trace from this coredump (don't ask me, I'm on windows)
    or something similar and go from there.

    Unless you meant a hardware exception. C++ doesn't deal with those
    kinds in its exception handling model but getting a stack trace from
    the coredump would help you find the offending code anyway.
     
    Me, Jun 9, 2005
    #3
  4. nrhayyal

    nrhayyal Guest

    thanks michiel for ur instant reply and thanks to "Me" for ur instant
    reply also.
    i have a catch(...) in my program ,but still its not caught in that
    block.
    let me explain the problem by putting few more details.

    suppose if i have a program p1 which has main().
    in p1 i have different types of catch blocks along with catch(...)
    in the try block of p1, i am calling one of the functions of p2, in p2
    i am calling p3 func(), in p3 i am calling p4 func() and so on upto
    p10.
    all these p2-p10 are programs.
    these programs are built and kept it as library functions , assume
    p2.a, p3.a .....p10.a.
    all these libraries are linked in the makefile of p1 and p1 is now my
    executable( or binary file u can say).
    i have no try-catch block in any of these libs.
    i have only throw statements in all these libs.

    so when an exception is thrown from p10.a library...... it is supposed
    to be caught in any of the catch blocks in p1. if not it should be
    caught atleast in catch(...).
    But in my module the thrown exception is not at all caught , instead of
    which i am getting coredump.
    i hope the problem is clearer now.
    i am using gcc-3.3.2 on AIX5.2.
    please let me know solution.
    thanks again to all of u friends.

    thanks & regards
    Nagaraj Hayyal
     
    nrhayyal, Jun 9, 2005
    #4
  5. nrhayyal

    David Guest

    On Thu, 9 Jun 2005 11:08:58 UTC, "nrhayyal" <>
    wrote:

    > thanks michiel for ur instant reply and thanks to "Me" for ur instant
    > reply also.
    > i have a catch(...) in my program ,but still its not caught in that
    > block.
    > let me explain the problem by putting few more details.
    >
    > suppose if i have a program p1 which has main().
    > in p1 i have different types of catch blocks along with catch(...)
    > in the try block of p1, i am calling one of the functions of p2, in p2
    > i am calling p3 func(), in p3 i am calling p4 func() and so on upto
    > p10.
    > all these p2-p10 are programs.
    > these programs are built and kept it as library functions , assume
    > p2.a, p3.a .....p10.a.
    > all these libraries are linked in the makefile of p1 and p1 is now my
    > executable( or binary file u can say).
    > i have no try-catch block in any of these libs.
    > i have only throw statements in all these libs.
    >
    > so when an exception is thrown from p10.a library...... it is supposed
    > to be caught in any of the catch blocks in p1. if not it should be
    > caught atleast in catch(...).
    > But in my module the thrown exception is not at all caught , instead of
    > which i am getting coredump.
    > i hope the problem is clearer now.
    > i am using gcc-3.3.2 on AIX5.2.
    > please let me know solution.
    > thanks again to all of u friends.
    >
    > thanks & regards
    > Nagaraj Hayyal


    You might want to check out the organization of your program and
    the underlying libraries and check for threads that you don't know
    /realize that are being created. It may be that your application
    only appears to be monolithic and handled by the catch(...) in
    your main code. Each new thread/fork will require a new try/catch
    mechanism to be effective.

    What does the coredump indicate your problem is? Are you perhaps
    getting some other kind of exception?

    What trace mechanism do you have besides the primary interface?
    Do you know what user/data actions cause the problem? Do your
    applications have some way of tracking the progress of activity.
    It helps you in finding evidence that Px started and never finished.
    You can then investigate the possibility that it contained the error.

    David
     
    David, Jun 9, 2005
    #5
  6. nrhayyal

    Howard Guest

    "nrhayyal" <> wrote in message
    news:...
    > thanks michiel for ur instant reply and thanks to "Me" for ur instant
    > reply also.
    > i have a catch(...) in my program ,but still its not caught in that
    > block.
    > let me explain the problem by putting few more details.
    >
    > suppose if i have a program p1 which has main().
    > in p1 i have different types of catch blocks along with catch(...)
    > in the try block of p1, i am calling one of the functions of p2, in p2
    > i am calling p3 func(), in p3 i am calling p4 func() and so on upto
    > p10.
    > all these p2-p10 are programs.
    > these programs are built and kept it as library functions , assume
    > p2.a, p3.a .....p10.a.
    > all these libraries are linked in the makefile of p1 and p1 is now my
    > executable( or binary file u can say).
    > i have no try-catch block in any of these libs.
    > i have only throw statements in all these libs.
    >
    > so when an exception is thrown from p10.a library...... it is supposed
    > to be caught in any of the catch blocks in p1. if not it should be
    > caught atleast in catch(...).
    > But in my module the thrown exception is not at all caught , instead of
    > which i am getting coredump.
    > i hope the problem is clearer now.
    > i am using gcc-3.3.2 on AIX5.2.
    > please let me know solution.
    > thanks again to all of u friends.
    >
    > thanks & regards
    > Nagaraj Hayyal
    >


    Perhaps one of the libraries you're linking against is itself referring to
    some dynamically-linked library? If that's the case, then the exception may
    be occurring in that dynamically-linked library, and is not able to throw a
    C++ exception up the chain. You should probably debug the problem, to see
    exactly where the error originates. (The core dump might give you some help
    with that, but I don't know UNIX that well to know how you'd tell.)

    -Howard
     
    Howard, Jun 9, 2005
    #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. SpreadTooThin

    uncaught throw.. (exception)

    SpreadTooThin, Aug 8, 2007, in forum: C++
    Replies:
    5
    Views:
    459
  2. George2

    Uncaught exception

    George2, Jan 28, 2008, in forum: C++
    Replies:
    3
    Views:
    512
    bjeremy
    Jan 28, 2008
  3. siddhu
    Replies:
    1
    Views:
    1,330
    Erik Wikström
    May 29, 2008
  4. Merlin
    Replies:
    0
    Views:
    104
    Merlin
    Sep 21, 2003
  5. friend
    Replies:
    1
    Views:
    226
    Thomas 'PointedEars' Lahn
    May 12, 2008
Loading...

Share This Page