The error class represents an error message.
It provides a uniform interface for error reporting and handling via the c++ exception mechanism.
Error exceptions may be caught and recovered from:
try { // open the console at 640x480 resolution console.open("Error example",640,480); } catch (Error&) { // fallback to default resolution console.open("Error example"); }
Or allowed to fall through to the main try/catch block and get reported to the user:
int main() { try { // open the console at 640x480 resolution console.open("Error example",640,480); } catch (Error &error) { // report error error.report(); } // exit return 0; }
Default constructor.
The error message is initialized to "".
Creates an error object with an error message of message.
Here is an example of typical use:
// do something ... bool failure = DoSomething(); // check failure if (failure) { // error message throw Error("do something failed"); }
Creates a error object with the text message and the error object message compounded.
The message parameter is the first line of the error message, a newline is inserted in the string, and the error object message is added to the end.
Here is an example of typical use:
try { // do something low level... bool failure = DoSomethingLowLevel(); // check failure if (failure) { // error message throw Error("low level failure"); } } catch (Error &error) { // error message throw Error("high level failure",error); }
The error message constructed in the catch block has a compound message of "high level failure\nlow level failure".
Copy constructor.
Destructor.
Reports the error and terminates the program with exit(1).
The error is reported in the most natural method of the platform.
For example, UNIX systems would print the error message to stderr, Win32 systems would display a message box, DOS systems would output to stdout etc.
Typically this function is used in combination with wrapping the main function with a try/catch block to ensure that all unhandled error exceptions are caught and reported to the user.
int main() { try { // main program ... } catch (Error &error) { // report error error.report(); } // exit return 0; }
Gets the error message string.
Assignment operator.
Equality operator.
Inequality operator.