Exceptions: Difference between revisions
Content deleted Content added
Line 52:
</ada>
=={{header|ALGOL 68}}==
ALGOL 68 uses event routines extensively in the "standard transput"▼
(stdio) to manage the various events that arise when data is read▼
(or written) to a file or external device.▼
===ALGOL 68 standard preclude "on event" routines===▼
The built in "on event" routines are:▼
* on char error - if the character transput (input or output) in cannot be converted to the standard character set.▼
* on format error - if the format specified is incompatable to the data being transput (input or output)▼
* on line end - if an end of line was read while the program was "transputting" data▼
* on logical file end - if the end of data was encounted during transput▼
* on page end - if the end of a page was encounted during transput▼
* on physical file end - if the end of physical media was encounted during transput▼
* on value error - if the data transput was incompatable with the variable tranput▼
All of the above allow the programmer to define a user created event▼
routine when a particular event happens to a particular FILE.▼
The handler is permitted to return TRUE depending on whether the event▼
has been handled and the program can can continue. And FALSE is when event▼
remains unhandled, and the standard preclude event routine should be used. The ▼
handler is also permitted to exit to a label (without returning anything) if the▼
user defined event routine determines that processing is complete.▼
===Define an exception===
<
# a user defined object #
MODE OBJECTFOO = STRUCT ( PROC (REF OBJECTFOO)BOOL foo event mended, ... );
Line 84 ⟶ 61:
);
</
===Raise an exception===
<
OBJECTFOO instance proxy := instance base; # event routines are specific to an instance #
Line 94 ⟶ 71:
OD;
</
Re-raising once caught exception:
<
...
except foo event:
Line 102 ⟶ 79:
IF NOT (foo event mended OF instance base)(instance base) THEN undefined # trace back # FI
FI
</
===Handle an exception===
<
PROC raise foo event(REF OBJECTFOO instance)BOOL:
IF mend foo(instance) THEN
Line 112 ⟶ 89:
FALSE # OR fall back to default event routine #
FI
</
▲ALGOL 68 uses event routines extensively in the "standard transput"
▲(stdio) to manage the various events that arise when data is read
▲(or written) to a file or external device.
▲The built in "on event" routines are:
▲* on char error - if the character transput (input or output) in cannot be converted to the standard character set.
▲* on format error - if the format specified is
▲* on line end - if an end of line was read while the program was "transputting" data
▲* on logical file end - if the end of data was encounted during transput
▲* on page end - if the end of a page was encounted during transput
▲* on physical file end - if the end of physical media was encounted during transput
▲* on value error - if the data transput was
▲All of the above allow the programmer to define a user created event
▲routine when a particular event happens to a particular FILE. When such an
event routine is called, then the routine can use any of the standard preclude
routine to reposition the FILE and rectify the detected event, eg:
* space or back space
* new line, new page, set or reset.
For example: these may notify the operator to mount a new tape (in the case of physical file end).
▲The handler is permitted to return TRUE depending on whether the event
▲has been handled and the program can can continue. And FALSE is when event
▲remains unhandled, and the standard preclude event routine should be used. The
▲handler is also permitted to exit to a label (without returning anything) if the
▲user defined event routine determines that processing is complete.
=={{header|AppleScript}}==
|