[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] ISO exceptions source
From: |
Gaius Mulley |
Subject: |
Re: [Gm2] ISO exceptions source |
Date: |
Wed, 23 Sep 2009 09:48:07 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
Martin Kalbfuß <address@hidden> writes:
> Hi,
>
> I try to use exceptions.
>
> I do for example:
>
> PROCEDURE VectorAddition(Vector1, Vector2 : ARRAY OF REAL;
> VAR Result : ARRAY OF REAL);
> VAR
> Index : CARDINAL;
> Source : EXCEPTIONS.ExceptionSource;
> BEGIN
> IF HIGH(Vector1) <> HIGH(Vector2) THEN
> EXCEPTIONS.AllocateSource(Source);
> EXCEPTIONS.RAISE(Source, 1, 'Error: Vectors of different size');
> END;
> FOR Index := 0 TO HIGH(Vector1) DO
> Result[Index] := Vector1[Index] + Vector2[Index];
> END;
> END VectorAddition;
>
>
> Is there anything I should do with the Source? Or should I only allocate
> it?
Hi Martin,
your code above would raise and exception appropriately - however if
you had multiple modules many of which could raise an exception you
wouldn't know which exception had been raised.
So I would perform the AllocateSource in the initialisation section of
the module and then provide another procedure function to test whether
the exception raised came from Source. Ie:
PROCEDURE VectorAddition(Vector1, Vector2 : ARRAY OF REAL;
VAR Result : ARRAY OF REAL);
VAR
Index : CARDINAL;
Source : EXCEPTIONS.ExceptionSource;
BEGIN
IF HIGH(Vector1) <> HIGH(Vector2) THEN
EXCEPTIONS.RAISE(Source, 1, 'Error: Vectors of different size');
END;
FOR Index := 0 TO HIGH(Vector1) DO
Result[Index] := Vector1[Index] + Vector2[Index];
END;
END VectorAddition;
PROCEDURE IsMyException () : BOOLEAN ;
(* Returns TRUE if the current coroutine is in the exceptional
execution state because of the raising of an exception from
Source; otherwise returns FALSE.
*)
BEGIN
RETURN( IsExceptionalExecution() AND IsCurrentSource(Source) )
END IsMyException ;
BEGIN
EXCEPTIONS.AllocateSource(Source);
END ...
have a look at gm2/gm2-libs-iso/IOChan.mod or
gm2/gm2-libs-iso/WholeConv.mod for some more ideas,
regards,
Gaius