U
usenet
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;
}
}
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;
}
}