Three levels of ambition:
Aim to control an exception in the part of the program where its effect can most sensibly be handled.
Example: tan(x) may be impossible to compute or represent
NUMERIC_ERROR exception can be detected and handled
Handle the exception locally; caller never realises anything was wrong.
function TAN (X : FLOAT) return FLOAT is begin return SIN(X) / COS(X); exception when NUMERIC_ERROR => if (SIN(X)>=0.0 and COS(X)>= 0.0) or (SIN(X)< 0.0 and COS(X)< 0.0) then return FLOAT'LAST; else return -FLOAT'LAST; end if; end TAN;
raise statement in exception handler:
function TAN (X : FLOAT) return FLOAT is begin return SIN(X) / COS(X); exception when NUMERIC_ERROR => PUT_LINE ("The value of tangent is too big"); raise; end TAN;
No example is needed of the third level of ambition. We are all familiar with that one! It is what we have been doing all the time up to now.