W
William Payne
Hello. Consider the following code snippet (pseudo-code).
void foo()
{
/* do stuff */
if fatal error occurs
{
throw "error message";
}
}
try
{
foo();
}
catch(/* what should go here if I want to display the error message from the
throw statement above? */)
{
/* display error message */
}
What do I need to do to if I want to obtain the error message from the
throw-statement? I tried catching std::exception but it didn't catch the
exception. Do I need to derive a new class from std::exception if I want to
display the error messages to the user of the program? That's really all I
need exceptions for right now. If a fatal error occur, throw exception to
break call chain and display error message to the user then exit program
(while logging some debugging information). So do I derive my own exception
type (which would be very simple indeed) or do I use some built-in type or
do I do something completely different?
Thanks
/ William Payne
void foo()
{
/* do stuff */
if fatal error occurs
{
throw "error message";
}
}
try
{
foo();
}
catch(/* what should go here if I want to display the error message from the
throw statement above? */)
{
/* display error message */
}
What do I need to do to if I want to obtain the error message from the
throw-statement? I tried catching std::exception but it didn't catch the
exception. Do I need to derive a new class from std::exception if I want to
display the error messages to the user of the program? That's really all I
need exceptions for right now. If a fatal error occur, throw exception to
break call chain and display error message to the user then exit program
(while logging some debugging information). So do I derive my own exception
type (which would be very simple indeed) or do I use some built-in type or
do I do something completely different?
Thanks
/ William Payne