473,545 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nested exception throwing

I wrote some sample code (see below) for nested exception throwing
i.e. my catch blocks are throwing exceptions of their own (for
simplicity I used standard exceptions). I am getting some extraneous
characters (St9) in my final output. Can anyone kindly help me
interpret that please?

Thanks,
Ramesh

Here's my output:
Exception bad_alloc in function func_level3()
Exception: Exception: Exception: St9bad_alloc in function
func_level2() in function func_level1() at xcptn-test.cpp,74

Here's my sample code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <sstream>
#include <stdexcept>
// Standard exceptions:-
// bad_alloc, bad_cast, bad_typeid,
bad_exception,
// logic_error, runtime_error,
ios_base::failu re
// domain_error, invalid_argumen t,
length_error
// out_of_range, range_error,
overflow_error,
// underflow_error

using namespace std;
//////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////
void
func_level3() throw (bad_alloc)
{
cerr << "Exception bad_alloc in function " << __func__ << "()\n";
throw bad_alloc();
}
//////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////
void
func_level2() throw (runtime_error)
{
try
{
func_level3();
}
catch(exception & xcptn)
{
ostringstream oss;
oss << "Exception: " << xcptn.what() << " in function " <<
__func__ << "()";
throw runtime_error(o ss.str());
}
}

//////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////
void
func_level1() throw (domain_error)
{
try
{
func_level2();
}
catch(exception & xcptn)
{
ostringstream oss;
oss << "Exception: " << xcptn.what() << " in function " <<
__func__ << "()";
throw domain_error(os s.str());
}
}
//////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////
main()
{
try
{
func_level1();
}
catch(exception & xcptn)
{
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ","
<< __LINE__ << endl;
}
}

May 19 '07 #1
1 3256

<us****@sta.sam sung.comwrote in message ...
I wrote some sample code (see below) for nested exception throwing
i.e. my catch blocks are throwing exceptions of their own (for
simplicity I used standard exceptions). I am getting some extraneous
characters (St9) in my final output. Can anyone kindly help me
interpret that please?
Thanks, Ramesh

Here's my output:
Exception bad_alloc in function func_level3()
Exception: Exception: Exception: St9bad_alloc in function
func_level2() in function func_level1() at xcptn-test.cpp,74
[ this is only my own theory/logic (i have not read-up on it) ]

GCC(g++) decorates the exception name. I believe that the 'St' stands for
'standard'(or 'standard template'). Someone else thought the '9' is the
number of characters that follow, and that seem to hold true for all I've
seen (in GCC).

What compiler are you using?
( Even though we don't discuss compilers here, it's sometimes helpful to
know which one gave the output.).

If you are deriving from std::exception, see my last post in this thread for
more:
Newsgroups: comp.lang.c++
Sent: Wednesday, May 16, 2007
Subject: exception and polymorphism problem

--
Bob R
POVrookie
May 19 '07 #2

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

Similar topics

5
1661
by: gh | last post by:
Hi, Is it true that the CLR sometimes can't throw the run time exception? Cause I have just encountered a problem that my program has some unexpected behaviours. After adding try-catch block to many pieces of code. It catches an array index out of bound exception. I am using VS.Net 2003 and is there any way to avoid this? Regards, Aaron
40
13473
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
2
5861
by: Rajeev Soni | last post by:
Hi, Considering the scenario for handling exceptions in Web Application where we have Presentation layer, Business layer and Data Access layer; if there any exception is occurred in DAL, what is the best thing to do: 1. Dont catch the exception in DAL and let it prop up to the Application level and the Global.Application_Error event log it...
2
4368
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
43
2078
by: Shehab Kamal | last post by:
Which approach is better: 1) Use a method that returns true/false (the method will log the exception that lead to false using log4net for example) OR 2) Use a method that returns void and throws an exception in case of failure? If the second approach is to be suggested: Should .NET predefined exceptions, NullReferenceException,...
5
3819
by: Bry | last post by:
I've created a class that offers an enhanced way of handling fatal exceptions. The class allows the user to optionaly submit a http based anonymous error report to myself, and also records details in the application log. The static method is overloaded, and supports passing exceptions and/or strings just like throwing an exception.The class...
24
2170
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from the UI layer to a method in a library class that calls the stored procedure. Best to return a boolean indicating success/failure, return a string with...
1
1178
by: chavali | last post by:
Hi, How to access the members of outerclass from a nested class. ie., for example class Class1 { class A { void show() { int y = x; }
8
2444
by: jayaramganapathy | last post by:
Hello friends, I have a map like std::map< std::string , std::map<std::string, std::string>* EpPropCache::propertyCache ; (This is a static instance and taken from *.cpp file) As you can see the value is a pointer to another map. I do new of std::map<std::string, std::stringand add the pointer to the map. Do I have to delete the map...
0
7416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7932
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7776
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6001
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5347
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
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 we have to send another system
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.