473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Debug exceptions

Hi,
These questions are on C++ and Exceptions.

1) How can I debug through gdb to find the location where exception
occured (Putting a breakpoint in exception handler will not help me as
the stack has already woundback and I have lost the information about
the code where it occured).

2) If I do "catch (...)", it will catch all exceptions. But in my
exception handler I want to know the type of exception that has
occured.

Note: I am using linux, gcc 3.4.3, gdb 6.1

Regards,
Seenu.

Feb 10 '06 #1
5 1807

se*****@gmail.com wrote:
Hi,
These questions are on C++ and Exceptions.

1) How can I debug through gdb to find the location where exception
occured (Putting a breakpoint in exception handler will not help me as
the stack has already woundback and I have lost the information about
the code where it occured).

2) If I do "catch (...)", it will catch all exceptions. But in my
exception handler I want to know the type of exception that has
occured.

Note: I am using linux, gcc 3.4.3, gdb 6.1

Regards,
Seenu.

catch(Type &exception)
{
}
I think.. Maybe I didn't understand your question
/Jesper

Feb 10 '06 #2
If I know the Type of the exception, then I can use the above syntax.
But if I am using
catch (...), I am not able to make out the exception.

For eg: If I know the exception, I can use "catch Type& e" and within
catch I can do cout of "e.what ()", but what if it is "catch (...)"?
Regards,
Seenu.

Feb 10 '06 #3
In article <11**********************@g44g2000cwa.googlegroups .com>,
se*****@gmail.com wrote:
Hi,
These questions are on C++ and Exceptions.

1) How can I debug through gdb to find the location where exception
occured (Putting a breakpoint in exception handler will not help me as
the stack has already woundback and I have lost the information about
the code where it occured).

2) If I do "catch (...)", it will catch all exceptions. But in my
exception handler I want to know the type of exception that has
occured.

Note: I am using linux, gcc 3.4.3, gdb 6.1


Best practice is to have all exception classes inherit from
std::exception, that way you can do "catch (const exception& e)" and
then query "e.what()" and hopefully that will give you a clue where it
came from.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 10 '06 #4
In article <11*********************@g47g2000cwa.googlegroups. com>,
se*****@gmail.com wrote:
If I know the Type of the exception, then I can use the above syntax.
But if I am using
catch (...), I am not able to make out the exception.

For eg: If I know the exception, I can use "catch Type& e" and within
catch I can do cout of "e.what ()", but what if it is "catch (...)"?


At the end of main, I often have something like this:

catch ( const exception& e ) {
// send e.what() to some error console
}
catch ( ... ) {
// send "unknown exception: who needs to die" to the error console
}

You see, if properly written, that catch(...) should never get used.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 10 '06 #5
<se*****@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
: If I know the Type of the exception, then I can use the above syntax.
: But if I am using
: catch (...), I am not able to make out the exception.
:
: For eg: If I know the exception, I can use "catch Type& e" and within
: catch I can do cout of "e.what ()", but what if it is "catch (...)"?

It is a recommended practice to derive all your custom exception
classes from std::exception, or a relevant subclass of it
(such as std::runtime_error).

The 'most generic' catch handling should then be:
catch( std::exception& x )
You can then access x.what() for a description of the error,
but also typeid(x).name() for a string that describes its
type (look up RTTI or typeid in your usual C++ reference).

Cheers,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Feb 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Mudd | last post by:
When debugging python, I add print statements such as these. print 'i=%s' % `i` print 'foo()=%s' % `foo()` print 'a,b,c=%s' % `a,b,c` I just want to dump the value of a variable or...
1
by: Raghunatha Babu | last post by:
Hi We are using the API "SetUnhandledExceptionFilter" to handle the exceptions globally as: SetUnhandledExceptionFilter(MyUnHandleExceptionFilter); where the prototype of...
1
by: Fredrik Melin | last post by:
Hi. I have run into trouble, I have a form that many of my forms inherits, the problem is in the IDE I can bring up the Base form into the form editor with no problem, but trying to bring up one...
5
by: Steve Le Monnier | last post by:
I've just noticed that the menu items available in Visual Studio 2005 for the Debug and Build menus differ significantly when compared to the menu items in Visual Studio 2003. On my C#...
5
by: Ben R. | last post by:
My website uses a custome membership and role provider. I can use a custom login control and user creation control and can debug my providers while doing so with breakpoints. However, when I launch...
7
by: tommaso.gastaldi | last post by:
It would be useful, sometimes, when debugging, to disable all the try /catch one has in the program (clearly not commenting them out). Any info or hint on that? -tom
7
by: iKiLL | last post by:
Hi all I am still pretty new to .Net and C#. I have come from a VB6 Background.
7
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I'm new to working with mixed assemblies. All of my previous experience has been with VC++/MFC in native, unmanaged applications. When I create a mixed assembly in which one or more of the files...
7
by: Jon Davis | last post by:
In order to gracefully handle exceptions at runtime but cause the debugger to break in the place where the exceptions occur when debugging, I used to write code like this: #if !DEBUG try {...
3
by: =?Utf-8?B?bG10dGFn?= | last post by:
We have developed a number of different applications (ASP.NET web site, Windows services, DLLs, Windows forms, etc.) in C# 2.0. We have developed and unit tested all these applications/components...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.