Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Nested exception throwing

Reply
Thread Tools

Nested exception throwing

 
 
usenet@sta.samsung.com
Guest
Posts: n/a
 
      05-19-2007
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;
}
}

 
Reply With Quote
 
 
 
 
BobR
Guest
Posts: n/a
 
      05-19-2007

<(E-Mail Removed)> wrote 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert.aspx throwing exception =?Utf-8?B?RXVzdGljZSBTY3J1YmI=?= ASP .Net 0 09-23-2005 03:51 AM
System.IO.Directoryinfo throwing exception =?Utf-8?B?R2xlbm4gVmVuemtl?= ASP .Net 3 07-25-2005 09:49 PM
WebRequest.GetResponse() throwing exception (Internal Server error =?Utf-8?B?VGVycnk=?= ASP .Net 4 01-13-2005 10:25 PM
Problem of throwing an exception (System.Net.Sockets.OverlappedAsyncResult::CompletionPortCallback) VincentWong ASP .Net 1 12-29-2003 09:32 AM
Throwing Exception in a composite control KJ ASP .Net 5 07-25-2003 01:33 PM



Advertisments