how to catch uncaught exception

N

nrhayyal

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
 
M

msalters

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
 
M

Me

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.
 
N

nrhayyal

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
 
D

David

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
 
H

Howard

nrhayyal said:
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
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top