473,398 Members | 2,403 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,398 software developers and data experts.

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::failure
// domain_error, invalid_argument,
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(oss.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(oss.str());
}
}
//////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////
main()
{
try
{
func_level1();
}
catch(exception& xcptn)
{
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ","
<< __LINE__ << endl;
}
}

May 19 '07 #1
1 3245

<us****@sta.samsung.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
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...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
2
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...
2
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
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...
5
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...
24
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...
1
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
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...

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.