"Fischlin Andreas" <andreas.fischlin@env.ethz.ch> writes:
Dear Phil,
Modula-2 has the philosophy of handling errors explicitly as the programer
strives to write an error free code in the first place. The only exceptions
that can
be considered are numerical ones, such as an integer or real overflow etc.,
which are detected and handled by the underlying hardware and system settings.
Depending on the current setting for the handling of such exceptions (tolerate
or respond etc.) this results typically in a HALT of the Modula-2 program with
some information on the causes of the exception and/or triggering of a debugger.
Hope this helps.
Sincerely yours,
Andreas Fischlin
ETH Zurich
Prof. em. Dr. Andreas Fischlin
Systems Ecology - Institute of Biogeochemistry and Pollutant Dynamics
CHN E 24
Universitaetstrasse 16
8092 Zurich
SWITZERLAND
andreas.fischlin@env.ethz.ch
https://sysecol.ethz.ch/people/andreas.fischlin.html
+41 44 633-6090 phone
+41 79 595-4050 mobile
Make it as simple as possible, but distrust it!
________________________________________________________________________
On 20 Dec 2023, at 04:20, Philip Munts <phil@munts.net> wrote:
Ada allows exception handling within each begin/end block, and
also allows a begin/end block inside a compound statement:
loop
begin
raise Program_Error;
exception
when Program_Error =>
...
end;
end loop;
Does GM2 allow something similar, or can exceptions be caught
only at the procedure or module level?
I like to use exceptions to propagate errors in Ada embedded
real-time software, since they can be caught and handled
anywhere along the calling chain or just ignored to abort the
program.
If exceptions can only be caught at procedure or module level
on the way out to a program abort, they are much less useful
to me.
Phil
Hi Andreas and Phil,
very true for pim[234] (I guess on some systems nil violation might be
caught by the underlying platform?). In iso exceptions are allowed but
only in the begin end blocks of modules and procedures.
An interesting exception example from the iso standard can be found in:
gcc/testsuite/gm2/iso/run/pass/except8.mod
http://cvs.savannah.nongnu.org/viewvc/gm2/testsuite/gm2/iso/run/pass/except8.mod?view=markup
(not that I'm advocating writing code like this :-). On a more
practical note the exception handling scheme works well and across
languages - and if using swig across into scripting languages. (Python3
can catch a m2 exception). In gm2 the procedure THROW is available from
the SYSTEM module and can be invoked from anywhere,
regards,
Gaius