Cryptography Reference
In-Depth Information
Exceptions in C++ are based principally on three types of constructs: the
try
block, the
catch
block, and the instruction
throw
, by means of which a
function signals an error. The first, the
catch
block, has the function of a local
error-handling routine for the
try
block: Errors that occur within a
try
block
and are announced by means of
throw
will be caught by the
catch
block, which
follows the
try
block. Further instructions of the
try
block are then ignored. The
type of error is indicated by the value of the
throw
instruction as parameter of the
accompanying expression.
The connection between
try
and
catch
blocks can be sketched as follows:
try
{
...
// If an error is signaled within an operation with
...
// throw, then it can be
...
// caught by the following catch block.
}
...
catch (argument)
{
...
// here follows the error handling routine.
}
If an error does not occur directly within a
try
block but in a function that is
called from there, then this function is terminated, and control is returned to the
calling function until, by following the chain of calls in reverse order, a function
within a
try
block is reached. From there control is passed to the appropriate
catch
block. If no
try
block is found, then the generic error routine appended
by the compiler is called, which then terminates the program, usually with some
nonspecific output.
It is clear what the errors are in the
LINT
class, and it would be a simple
possibility to call
throw
with the error codes, which are provided to the
panic()
routine by the
LINT
functions and operators. However, the following solution
offers a bit more comfort: We define an abstract base class
class LINT_Error
{
public:
char* function, *module;
int argno, lineno;
virtual void debug_print (void) const = 0; // pure virtual
virtual
˜
LINT_Error() {function = 0; module = 0;};
};