| 1 |
(* GeneralUserExceptions.mod implement the ISO GeneralUserExceptions. |
| 2 |
|
| 3 |
Copyright (C) 2002-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 GeneralUserExceptions ; |
| 28 |
|
| 29 |
FROM EXCEPTIONS IMPORT ExceptionSource, RAISE, AllocateSource, CurrentNumber, |
| 30 |
IsCurrentSource, IsExceptionalExecution ; |
| 31 |
|
| 32 |
FROM M2RTS IMPORT NoException ; |
| 33 |
FROM SYSTEM IMPORT ADR ; |
| 34 |
|
| 35 |
|
| 36 |
VAR |
| 37 |
general: ExceptionSource ; |
| 38 |
|
| 39 |
|
| 40 |
(* |
| 41 |
RaiseGeneralException - raises exception using text as the associated |
| 42 |
message. |
| 43 |
*) |
| 44 |
|
| 45 |
PROCEDURE RaiseGeneralException (exception: GeneralExceptions; text: ARRAY OF CHAR) ; |
| 46 |
BEGIN |
| 47 |
RAISE (general, ORD (exception), text) |
| 48 |
END RaiseGeneralException ; |
| 49 |
|
| 50 |
|
| 51 |
(* |
| 52 |
IsGeneralException - returns TRUE if the current coroutine is in the |
| 53 |
exceptional execution state because of the raising |
| 54 |
of an exception from GeneralExceptions; otherwise |
| 55 |
returns FALSE. |
| 56 |
*) |
| 57 |
|
| 58 |
PROCEDURE IsGeneralException () : BOOLEAN ; |
| 59 |
BEGIN |
| 60 |
RETURN IsExceptionalExecution () AND IsCurrentSource (general) |
| 61 |
END IsGeneralException ; |
| 62 |
|
| 63 |
|
| 64 |
(* |
| 65 |
GeneralException - if the current coroutine is in the exceptional |
| 66 |
execution state because of the raising of an |
| 67 |
exception from GeneralExceptions, returns the |
| 68 |
corresponding enumeration value, and otherwise |
| 69 |
raises an exception. |
| 70 |
*) |
| 71 |
|
| 72 |
PROCEDURE GeneralException () : GeneralExceptions; |
| 73 |
BEGIN |
| 74 |
IF IsGeneralException () |
| 75 |
THEN |
| 76 |
RETURN VAL (GeneralExceptions, CurrentNumber (general)) |
| 77 |
ELSE |
| 78 |
NoException (ADR (__FILE__), __LINE__, |
| 79 |
__COLUMN__, ADR (__FUNCTION__), |
| 80 |
ADR ("not in the exceptional execution state")) |
| 81 |
END |
| 82 |
END GeneralException ; |
| 83 |
|
| 84 |
|
| 85 |
BEGIN |
| 86 |
AllocateSource (general) |
| 87 |
END GeneralUserExceptions. |