| 1 |
(* M2EXCEPTION.mod implement M2Exception and IsM2Exception. |
| 2 |
|
| 3 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
Under Section 7 of GPL version 3, you are granted additional |
| 19 |
permissions described in the GCC Runtime Library Exception, version |
| 20 |
3.1, as published by the Free Software Foundation. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License and |
| 23 |
a copy of the GCC Runtime Library Exception along with this program; |
| 24 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 25 |
<http://www.gnu.org/licenses/>. *) |
| 26 |
|
| 27 |
IMPLEMENTATION MODULE M2EXCEPTION ; |
| 28 |
|
| 29 |
FROM SYSTEM IMPORT ADR ; |
| 30 |
FROM RTExceptions IMPORT EHBlock, GetExceptionBlock, GetNumber, Raise, |
| 31 |
SetExceptionBlock, InitExceptionBlock ; |
| 32 |
|
| 33 |
|
| 34 |
(* If the program or coroutine is in the exception state then return the enumeration |
| 35 |
value representing the exception cause. If it is not in the exception state then |
| 36 |
raises an exException exception. *) |
| 37 |
|
| 38 |
PROCEDURE M2Exception () : M2Exceptions; |
| 39 |
VAR |
| 40 |
e: EHBlock ; |
| 41 |
n: CARDINAL ; |
| 42 |
BEGIN |
| 43 |
e := GetExceptionBlock () ; |
| 44 |
n := GetNumber (e) ; |
| 45 |
IF n = MAX (CARDINAL) |
| 46 |
THEN |
| 47 |
Raise (ORD (exException), ADR (__FILE__), __LINE__, __COLUMN__, ADR (__FUNCTION__), |
| 48 |
ADR ('current coroutine is not in the exceptional execution state')) ; |
| 49 |
RETURN exException |
| 50 |
ELSE |
| 51 |
RETURN VAL (M2Exceptions, n) |
| 52 |
END |
| 53 |
END M2Exception ; |
| 54 |
|
| 55 |
|
| 56 |
(* Returns TRUE if the program or coroutine is in the exception state. |
| 57 |
Returns FALSE if the program or coroutine is not in the exception state. *) |
| 58 |
|
| 59 |
PROCEDURE IsM2Exception () : BOOLEAN; |
| 60 |
VAR |
| 61 |
e: EHBlock ; |
| 62 |
BEGIN |
| 63 |
e := GetExceptionBlock () ; |
| 64 |
RETURN GetNumber (e) # MAX (CARDINAL) |
| 65 |
END IsM2Exception ; |
| 66 |
|
| 67 |
|
| 68 |
BEGIN |
| 69 |
SetExceptionBlock (InitExceptionBlock ()) |
| 70 |
END M2EXCEPTION. |