Exception architecture, Error handlers – HP Integrity NonStop J-Series User Manual

Page 254

Advertising
background image

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Exception Architecture

When an exception is thrown a throw operand is passed. The type of the throw operand determines which
handlers can catch it. Tools.h++ uses the following hierarchy for throw operands:

xmsg
RWxmsg
RWInternalErr
RWBoundsErr
RWExternalErr
RWFileErr
RWStreamErr
xalloc
RWxalloc

As you can see, the hierarchy parallels the error model outlined in the first part of this chapter. This
hierarchy assumes the presence of class xmsg, nominally provided by your compiler vendor. This is the
class now being considered for standardization by the Library Working Group of the C++ Standardization
Committee X3J16 (Document 92-0116). If your compiler does not come with versions of xmsg and xalloc,
the Rogue Wave classes RWxmsg and RWxalloc will emulate them for you.

Class xmsg carries a string that can be printed out at the catch site to give the user some idea of what went
wrong. This string is formatted and internationalized as described in

Chapter 16 (

Localizing Messages

)

.

Error Handlers

Tools.h++ uses the macro RWTHROW to throw an exception. If your compiler supports exceptions, this
macro resolves by calling a function which throws the exception. If your compiler does not support
exceptions, the macro resolves to call an error handler with prototype:

void errHandler(const RWxmsg&);

The default error handler aborts the program. You can change the default handler with the function:

typedef void (*rwErrHandler)(const RWxmsg&);
rwErrHandler rwSetErrHandler(rwErrHandler);

The next example demonstrates how a user-defined error handler works in a compiler that doesn't support
exceptions:

#include <rw/rwerr.h>
#include <rw/coreerr.h>
#include <iostream.h>

#ifdef RW_NO_EXCEPTIONS

Advertising
This manual is related to the following products: