Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members

# ptc::Error Class Reference

An error message. More...

List of all members.

## Public Members

- Error ()
- Error (const char message[])
- Error (const char message[],const Error &error)
- Error (const Error &error)
- ~Error ()
- void report () const
- const char* message () const
- Error& operator= (const Error &error)
- bool operator== (const Error &error) const
- bool operator!= (const Error &error) const

## Detailed Description

An error message.

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

## Member Function Documentation

### ptc::Error::Error ()

Default constructor.

The error message is initialized to "".

### ptc::Error::Error (const char message[])

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");
                }

Parameters:
  message - the error message.

### ptc::Error::Error (const char message[], const Error & error)

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".

Parameters:
  message - the error message.
  error - the compounding error.

### ptc::Error::Error (const Error & error)

Copy constructor.

### ptc::Error::~Error ()

Destructor.

### void ptc::Error::report () const

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

### const char * ptc::Error::message () const

Gets the error message string.

Returns:
  The error message.

### Error & ptc::Error::operator= (const Error & error)

Assignment operator.

### bool ptc::Error::operator== (const Error & error) const

Equality operator.

### bool ptc::Error::operator!= (const Error & error) const

Inequality operator.

The documentation for this class was generated from the following file:

- ptc.h