473,473 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Rethrowing an Exception -- Core Dump

I am trying to overcome the following hurdle. We have several
exception types, derived from a "BaseException" type.

Lets say SpecialException inherits from BaseException.

Lets say a SpecialException is thrown, and handled by try/catch that
is catching "BaseException".

If I retry to throw this exception, I get a core dump.

Here is a short program I wrote to show the error point:

#include <string>
using namespace std;

class BaseException {};

class SpecialException : public BaseException {};

int main()
{
try
{
SpecialException lSpecialException;
throw lSpecialException;
}
catch (BaseException ipBaseException)
{
throw;
}
}
The core dump I get looks like this:

#0 0xb73eac0f in raise () from /lib/tls/libc.so.6
#1 0xb73ec415 in abort () from /lib/tls/libc.so.6
#2 0xb75b1527 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3 0xb75b1574 in std::terminate () from /usr/lib/libstdc++.so.5
#4 0xb75b174c in __cxa_rethrow () from /usr/lib/libstdc++.so.5
#5 0x0804869f in main ()
(gdb)
Anything I can do to overcome this hurdle, without explicitly handling
all the sub exception types?

Thanks,
AJ

Oct 22 '07 #1
5 6431
aj
I figured out the problem. My test program wasn't accurate anyway, as
it needs an extra level of try/catch to showcase the problem.

Oct 22 '07 #2
je*********@gmail.com wrote:
I am trying to overcome the following hurdle. We have several
exception types, derived from a "BaseException" type.

Lets say SpecialException inherits from BaseException.

Lets say a SpecialException is thrown, and handled by try/catch that
is catching "BaseException".

If I retry to throw this exception, I get a core dump.

Here is a short program I wrote to show the error point:

#include <string>
using namespace std;

class BaseException {};

class SpecialException : public BaseException {};

int main()
{
try
{
SpecialException lSpecialException;
throw lSpecialException;
}
catch (BaseException ipBaseException)
catch (BaseException& ipBaseException)
{
throw;
}
}
Catch by reference, otherwise you get slicing.
Oct 22 '07 #3
On Oct 22, 3:34 pm, jerseyca...@gmail.com wrote:
I am trying to overcome the following hurdle. We have several
exception types, derived from a "BaseException" type.

Lets say SpecialException inherits from BaseException.

Lets say a SpecialException is thrown, and handled by try/catch that
is catching "BaseException".

If I retry to throw this exception, I get a core dump.

Here is a short program I wrote to show the error point:

#include <string>
using namespace std;

class BaseException {};

class SpecialException : public BaseException {};

int main()
{
try
{
SpecialException lSpecialException;
throw lSpecialException;
}
catch (BaseException ipBaseException)
{
throw;
}

}

The core dump I get looks like this:

#0 0xb73eac0f in raise () from /lib/tls/libc.so.6
#1 0xb73ec415 in abort () from /lib/tls/libc.so.6
#2 0xb75b1527 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3 0xb75b1574 in std::terminate () from /usr/lib/libstdc++.so.5
#4 0xb75b174c in __cxa_rethrow () from /usr/lib/libstdc++.so.5
#5 0x0804869f in main ()
(gdb)

Anything I can do to overcome this hurdle, without explicitly handling
all the sub exception types?

Thanks,
AJ
The reason you are getting a core is because when you are rethrowing
the exception, there is no catch handler. It just propogates out of
main() which is a no-no
Lance

Oct 22 '07 #4
je*********@gmail.com wrote:
I am trying to overcome the following hurdle. We have several
exception types, derived from a "BaseException" type.

Lets say SpecialException inherits from BaseException.

Lets say a SpecialException is thrown, and handled by try/catch that
is catching "BaseException".

If I retry to throw this exception, I get a core dump.

Here is a short program I wrote to show the error point:

#include <string>
using namespace std;

class BaseException {};

class SpecialException : public BaseException {};

int main()
{
try
{
SpecialException lSpecialException;
throw lSpecialException;
}
catch (BaseException ipBaseException)
{
throw;
}
}
The core dump I get looks like this:

#0 0xb73eac0f in raise () from /lib/tls/libc.so.6
#1 0xb73ec415 in abort () from /lib/tls/libc.so.6
#2 0xb75b1527 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3 0xb75b1574 in std::terminate () from /usr/lib/libstdc++.so.5
#4 0xb75b174c in __cxa_rethrow () from /usr/lib/libstdc++.so.5
#5 0x0804869f in main ()
(gdb)
Anything I can do to overcome this hurdle, without explicitly handling
all the sub exception types?
What do you explect? If you 'throw;' out of a catch block, you need
another try/catch clauses to catch your exception. You don't have them,
so your 'terminate' is duly called.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 22 '07 #5
red floyd wrote:
>
Catch by reference, otherwise you get slicing.
Yes, but that's not his problem. Rethrow always
rethrows the current exception, not the copy made
in the catch block.
Oct 23 '07 #6

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

Similar topics

12
by: Ritz, Bruno | last post by:
hi in java i found that when a method has a throws clause in the definition, callers must either handle the exceptions thrown by the method they are calling or "forward" the exception to the...
27
by: garyolsen | last post by:
In C++ what kind of unexpected conditions should be handled as exceptions? Besides dividing by 0, bad memory allocation, what're the most popular exceptions? When should not use exception,...
28
by: Scott Brady Drummonds | last post by:
Hi, all, I just got out of a meeting with a team of software developers that I recently joined as they are staffing to create a medium-sized project (potentially all of which will be written in...
3
by: vulcan.wayne | last post by:
Hi Shouldn't this code cause a core dump when the sys runs out of mem, when there's no default exception handling mechanism. void fn() { SomeObj *so = NULL; so = new SomeObj; // -> no...
6
by: Chris Newcombe | last post by:
Please could someone on the VC++ 7.0 compiler team (note; not 7.1) tell me if this code is handled 'correctly' (i.e. as the original poster suggests) in all cases? ...
5
by: Steven T. Hatton | last post by:
I haven't thought about rethrowing an exception in a long time, and tried to do it the wrong way. Now I'm curious about /why/ it's wrong. My expectation was that the exception instance would...
15
by: =?Utf-8?B?TWljaGVsIFBvc3NldGggW01DUF0=?= | last post by:
In my opinion rethrowing exceptions without providing anny extra information is a totall waste Examples : in my opinion wrong : A: Public sub DoSomeStuff() Try do it
1
by: Ami | last post by:
We have an application where in SOAP is used as a middle layer to communication between Java Front layer and DCE( Distributed Computing Env) backend layer. We are using Systinet Server for C++ to...
6
by: wenmang | last post by:
Hi, all, I am trying to allocate some objects during application starts up. The objects are created through new operator, but for some reason, the application keeps crashing and here is the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.