M
masood.iqbal
In all the sample code snippets of try-catch code blocks that I have
seen, the catch block does one of the following three things:
1). exits the program (after spitting out a cerr message)
2). propagates the exception
3). throws yet another exception
I have a need to do something different. I want to merely spit out a
cerr message when I catch an exception, and then proceed with my
business logic. I am thinking of something like this:
////// Code snippet begin /////
bool noException = true;
try
{
// some business logic operation
}
catch(std::exception& xcptn)
{
noException = false;
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ","
<< __LINE__ << endl;
cerr << "Ignoring business logic operation\n";
}
catch(...)
{
noException = false;
cerr << "Unrecognized exception at " << __FILE__ << "," << __LINE__
<< endl;
cerr << "Ignoring business logic operation\n";
}
if(noException)
{
// proceed with this business logic operation
}
////// Code snippet end /////
Am I doing it right, or is there a more professional way to do it?
Thanks,
Masood
seen, the catch block does one of the following three things:
1). exits the program (after spitting out a cerr message)
2). propagates the exception
3). throws yet another exception
I have a need to do something different. I want to merely spit out a
cerr message when I catch an exception, and then proceed with my
business logic. I am thinking of something like this:
////// Code snippet begin /////
bool noException = true;
try
{
// some business logic operation
}
catch(std::exception& xcptn)
{
noException = false;
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ","
<< __LINE__ << endl;
cerr << "Ignoring business logic operation\n";
}
catch(...)
{
noException = false;
cerr << "Unrecognized exception at " << __FILE__ << "," << __LINE__
<< endl;
cerr << "Ignoring business logic operation\n";
}
if(noException)
{
// proceed with this business logic operation
}
////// Code snippet end /////
Am I doing it right, or is there a more professional way to do it?
Thanks,
Masood