Overview

You can respond to an unrecoverable error condition by raising an exception using the berr macro, which has an interface similar to that of cout. The binding will catch the exception and return it correctly to the framework.

Usage

Mixed Content Messages

C++ Source Code (against 1199)
berr << messages << messages << ...;

where messages can be anything that you would normally pass to cout, for example string literals, STL strings, or numerics. At the end of the statement, an exception is raised.

Error Codes

If the first item passed to berr is a Symbol, and it is an error code (S_ERROR(symbol) returns non-zero), then it is propagated to the framework as an error code. For example,

C++ Source Code (against 1199)
berr << E_MEMORY << "4MB requested";

will generate a formatted E_MEMORY error message. Note the (probably very rare) gotcha, then, that if you try the following,

C++ Source Code (against 1199)
berr << (UINT32)0xE1234567 << " is not a valid parameter";

you will get a garbled error message because the number will be interpreted as an error code. In this rare case, you should format your error message so that this can't happen by prepending the error code that is implied by the above, anyway, thus:

C++ Source Code (against 1199)
berr << E_USER << (UINT32)0xE1234567 << " is not a valid parameter";

Example

C++ Source Code (against 1199)
UINT32 N = 7; const char* X = "quantum effects"; berr << "i knew you were going to do " << N << " things wrong..."; berr << E_REALITY_INVERSION << "this code can't be reached... " << "have you considered " << X << "?";