* Re: Ada 0x, exception idea ?
[not found] <3F229597.3090909@myob.com>
@ 2003-07-27 11:42 ` sk
2003-07-27 15:33 ` Nick Roberts
2003-07-28 0:23 ` Wesley Groleau
2003-07-27 15:51 ` sk
` (2 subsequent siblings)
3 siblings, 2 replies; 25+ messages in thread
From: sk @ 2003-07-27 11:42 UTC (permalink / raw)
To: comp.lang.ada
wesgroleau@myrealbox.com :
> case C_function (params) is
>
> when 0 => null; -- success
> when Bummer => raise Its_a_Bummer;
> when Darn => raise Darn_it;
> when Blast => raise Blast_It;
> when Disaster => raise Program_Error;
>
This still seems a bit "visually-bulky" (for want
of a better expression) but interesting and cleaner
than possible pages of "if-then-elsif" before
resuming with the original purpose of the algorithm.
> and some folks thought
>
> raise <exception> when <condition>;
>
> should be there as well. But it was rejected.
>
Is this discussed in the Ada95 Rationale ? If not,
where ?
As a related idea, is there thought/discussion
about adding a mechanism to attach and retrieve
error codes to an exception for later processing
in the exception handler ?
--
-------------------------------------------------
-- Merge vertically for real address
--
-- s n p @ t . o
-- k i e k c c m
-------------------------------------------------
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 11:42 ` Ada 0x, exception idea ? sk
@ 2003-07-27 15:33 ` Nick Roberts
2003-07-27 17:13 ` Samuel Tardieu
2003-07-28 0:23 ` Wesley Groleau
1 sibling, 1 reply; 25+ messages in thread
From: Nick Roberts @ 2003-07-27 15:33 UTC (permalink / raw)
My apologies for my news server, which seems to be missing certain posts in
this thread.
I cannot find a relevant AI (or AC), but I am fairly sure that people have
hinted that the ARG is more or less determined to replace the existing
syntax for a raise statement with:
RAISE [exception_name] [WHEN expression];
The form with the 'when' reserved word would indeed be syntactic sugar,
exactly equivalent to:
IF expression THEN RAISE [exception_name]; END IF;
I think it's generally felt that this change is worthwhile because it should
be extremely easy to make, harmless (to existing code), safe (re code
intelligibility), and useful (if only slightly).
"sk" <noname@myob.com> wrote in message
news:mailman.5.1059306172.320.comp.lang.ada@ada.eu.org...
> As a related idea, is there thought/discussion
> about adding a mechanism to attach and retrieve
> error codes to an exception for later processing
> in the exception handler ?
Such a mechanism already exists. Look in the Reference Manual, chapter 11.
--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 15:33 ` Nick Roberts
@ 2003-07-27 17:13 ` Samuel Tardieu
2003-07-28 12:41 ` Nick Roberts
0 siblings, 1 reply; 25+ messages in thread
From: Samuel Tardieu @ 2003-07-27 17:13 UTC (permalink / raw)
>>>>> "Nick" == Nick Roberts <nickroberts@blueyonder.co.uk> writes:
Nick> RAISE [exception_name] [WHEN expression];
Nick> I think it's generally felt that this change is worthwhile
Nick> because it should be extremely easy to make, harmless (to
Nick> existing code), safe (re code intelligibility), and useful (if
Nick> only slightly).
How would you integrate this with Ada.Exceptions.Raise_Exception?
(to attach an error message to the exception occurrence)
RAISE [exception_name] WITH [exception_message] [WHEN expression] ?
Would expression be evaluated before or after exception_message? Would
exception_message be evaluated at all if the test is wrong?
Sam
--
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 17:13 ` Samuel Tardieu
@ 2003-07-28 12:41 ` Nick Roberts
0 siblings, 0 replies; 25+ messages in thread
From: Nick Roberts @ 2003-07-28 12:41 UTC (permalink / raw)
"Samuel Tardieu" <sam@rfc1149.net> wrote in message
news:87smorj3kp.fsf@inf.enst.fr...
> How would you integrate this with Ada.Exceptions.Raise_Exception?
> (to attach an error message to the exception occurrence)
>
> RAISE [exception_name] WITH [exception_message] [WHEN expression] ?
> Would expression be evaluated before or after exception_message? Would
> exception_message be evaluated at all if the test is wrong?
I don't think I would want to go so far, and I'm 99% certain the ARG
wouldn't even consider it (for the next revision). If you want a message,
you just have to write:
if condition then
Ada.Exceptions.Raise_Exception(exception'Identity,message);
end if;
Too bad. I think a typical debugging package would have an inlined procedure
such as:
Ensure( condition[, message] );
which would test the 'condition', and raise e.g. Debugging_Error if it is
false, setting the exception's message to 'message' if supplied.
--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 11:42 ` Ada 0x, exception idea ? sk
2003-07-27 15:33 ` Nick Roberts
@ 2003-07-28 0:23 ` Wesley Groleau
2003-07-28 2:46 ` John R. Strohm
1 sibling, 1 reply; 25+ messages in thread
From: Wesley Groleau @ 2003-07-28 0:23 UTC (permalink / raw)
sk wrote:
> wesgroleau@myrealbox.com :
> > case C_function (params) is
> >
> > when 0 => null; -- success
> > when Bummer => raise Its_a_Bummer;
> > when Darn => raise Darn_it;
> > when Blast => raise Blast_It;
> > when Disaster => raise Program_Error;
> >
> This still seems a bit "visually-bulky" (for want
> of a better expression) but interesting and cleaner
> than possible pages of "if-then-elsif" before
> resuming with the original purpose of the algorithm.
Why is the above (which works now) more "bulky"
than the requested
raise Its_A_Bummer when Result = Bummer;
raise Darn_It when Result = Darn;
raise Blast_It when Result = Blast;
etc.
??
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-28 0:23 ` Wesley Groleau
@ 2003-07-28 2:46 ` John R. Strohm
2003-07-28 3:23 ` Hyman Rosen
2003-07-28 3:24 ` Hyman Rosen
0 siblings, 2 replies; 25+ messages in thread
From: John R. Strohm @ 2003-07-28 2:46 UTC (permalink / raw)
"Wesley Groleau" <wesgroleau@myrealbox.com> wrote in message
news:LGadnTxRQ9xh8bmiU-KYvg@gbronline.com...
> sk wrote:
> > wesgroleau@myrealbox.com :
> > > case C_function (params) is
> > >
> > > when 0 => null; -- success
> > > when Bummer => raise Its_a_Bummer;
> > > when Darn => raise Darn_it;
> > > when Blast => raise Blast_It;
> > > when Disaster => raise Program_Error;
> > >
> > This still seems a bit "visually-bulky" (for want
> > of a better expression) but interesting and cleaner
> > than possible pages of "if-then-elsif" before
> > resuming with the original purpose of the algorithm.
>
> Why is the above (which works now) more "bulky"
> than the requested
>
> raise Its_A_Bummer when Result = Bummer;
> raise Darn_It when Result = Darn;
> raise Blast_It when Result = Blast;
Observe that you get PRECISELY the same result with
if Result = Bummer then raise Its_A_Bummer; end if;
if Result = Darn then raise Darn_It; end if;
if Result = Blast then raise Blast_It; end if;
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
[not found] <3F229597.3090909@myob.com>
2003-07-27 11:42 ` Ada 0x, exception idea ? sk
@ 2003-07-27 15:51 ` sk
2003-07-27 17:22 ` Nick Roberts
2003-07-28 0:21 ` sk
2003-07-28 11:24 ` sk
3 siblings, 1 reply; 25+ messages in thread
From: sk @ 2003-07-27 15:51 UTC (permalink / raw)
To: comp.lang.ada
nickroberts@blueyonder.co.uk:
> Such a mechanism already exists. Look in the Reference Manual,
> chapter 11.
Are you actually refering to chapter 12 and package Ada.Exceptions ?
("Ada95 Reference Manual" supplied with GNAT 3.15p documentaion)
If so, I was refering to an Integer type error code value rather
than attaching a string message using the Raise_Exception procedure.
--
-------------------------------------------------
-- Merge vertically for real address
--
-- s n p @ t . o
-- k i e k c c m
-------------------------------------------------
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 15:51 ` sk
@ 2003-07-27 17:22 ` Nick Roberts
2003-07-27 19:30 ` sk
2003-07-28 0:07 ` sk
0 siblings, 2 replies; 25+ messages in thread
From: Nick Roberts @ 2003-07-27 17:22 UTC (permalink / raw)
"sk" <noname@myob.com> wrote in message
news:mailman.6.1059321078.320.comp.lang.ada@ada.eu.org...
> Are you actually refering to chapter 12 and package Ada.Exceptions ?
> ("Ada95 Reference Manual" supplied with GNAT 3.15p documentaion)
RM95 11.4.1 The Package Exceptions.
> If so, I was refering to an Integer type error code value rather
> than attaching a string message using the Raise_Exception procedure.
I think the idea is that you encode the integer into the string, and decode
it out again, if need be. Certainly not elegant, but workable. (Speed is
unlikely to be a concern.)
--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 17:22 ` Nick Roberts
@ 2003-07-27 19:30 ` sk
2003-07-27 23:04 ` John R. Strohm
2003-07-28 0:07 ` sk
1 sibling, 1 reply; 25+ messages in thread
From: sk @ 2003-07-27 19:30 UTC (permalink / raw)
To: comp.lang.ada
nickroberts@blueyonder.co.uk:
> RM95 11.4.1 The Package Exceptions.
Interesting,
" ADA REFERENCE MANUAL
"
" Language and Standard Libraries
"
" Version 6.0
Which resides in ".../gnat-3.15p-unx-docs/html/arm95.html"
" 12.4.1 The Package Exceptions
... so it would seem that there are different LRM's floating
about which I will have to track down :-(
> I think the idea is that you encode the integer into the string,
> and decode it out again, if need be. Certainly not elegant, but
> workable. (Speed is unlikely to be a concern.)
Yuck :-)
--
-------------------------------------------------
-- Merge vertically for real address
--
-- s n p @ t . o
-- k i e k c c m
-------------------------------------------------
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 19:30 ` sk
@ 2003-07-27 23:04 ` John R. Strohm
0 siblings, 0 replies; 25+ messages in thread
From: John R. Strohm @ 2003-07-27 23:04 UTC (permalink / raw)
"sk" <noname@myob.com> wrote in message
news:mailman.7.1059334209.320.comp.lang.ada@ada.eu.org...
> nickroberts@blueyonder.co.uk:
> > RM95 11.4.1 The Package Exceptions.
>
> Interesting,
>
> " ADA REFERENCE MANUAL
> "
> " Language and Standard Libraries
> "
> " Version 6.0
>
> Which resides in ".../gnat-3.15p-unx-docs/html/arm95.html"
>
> " 12.4.1 The Package Exceptions
>
> ... so it would seem that there are different LRM's floating
> about which I will have to track down :-(
>
>
> > I think the idea is that you encode the integer into the string,
> > and decode it out again, if need be. Certainly not elegant, but
> > workable. (Speed is unlikely to be a concern.)
>
> Yuck :-)
Exceptions are NOT intended to be used for "normal" situations.
They are intended to be used for HIGHLY UNUSUAL situations, that MUST be
dealt with.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-27 17:22 ` Nick Roberts
2003-07-27 19:30 ` sk
@ 2003-07-28 0:07 ` sk
2003-07-28 0:27 ` Wesley Groleau
2003-07-28 2:50 ` John R. Strohm
1 sibling, 2 replies; 25+ messages in thread
From: sk @ 2003-07-28 0:07 UTC (permalink / raw)
To: comp.lang.ada
strohm@airmail.net:
> Exceptions are NOT intended to be used for "normal" situations.
>
> They are intended to be used for HIGHLY UNUSUAL situations, that
> MUST be dealt with.
Of course, but that should not require one to implement a text
parser to determine the cause of errors.
--
-------------------------------------------------
-- Merge vertically for real address
--
-- s n p @ t . o
-- k i e k c c m
-------------------------------------------------
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-28 0:07 ` sk
@ 2003-07-28 0:27 ` Wesley Groleau
2003-07-28 2:50 ` John R. Strohm
1 sibling, 0 replies; 25+ messages in thread
From: Wesley Groleau @ 2003-07-28 0:27 UTC (permalink / raw)
> Of course, but that should not require one to implement a text
> parser to determine the cause of errors.
The compiler vendor already implemented it for you:
exception
when E : others =>
case Error_Type'Value(Ada.Exceptions.Exception_Message(E)) is
when 1 =>
Handle_Error_One;
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
2003-07-28 0:07 ` sk
2003-07-28 0:27 ` Wesley Groleau
@ 2003-07-28 2:50 ` John R. Strohm
1 sibling, 0 replies; 25+ messages in thread
From: John R. Strohm @ 2003-07-28 2:50 UTC (permalink / raw)
"sk" <noname@myob.com> wrote in message
news:mailman.8.1059350842.320.comp.lang.ada@ada.eu.org...
> strohm@airmail.net:
> > Exceptions are NOT intended to be used for "normal" situations.
> >
> > They are intended to be used for HIGHLY UNUSUAL situations, that
> > MUST be dealt with.
>
> Of course, but that should not require one to implement a text
> parser to determine the cause of errors.
I must be extraordinarily dense today, because I fail utterly to comprehend
what you are trying to say. Ada already provides you with access to the
exception name, without parsing text, viz.
begin
call_some_procedure_that_might_barf(params);
exception
when constraint_error => handle_constraint_error(params);
when program_error => handle_program_error(params);
when others => raise;
end;
Would you please clarify?
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
[not found] <3F229597.3090909@myob.com>
2003-07-27 11:42 ` Ada 0x, exception idea ? sk
2003-07-27 15:51 ` sk
@ 2003-07-28 0:21 ` sk
2003-07-28 8:38 ` Preben Randhol
2003-07-28 11:24 ` sk
3 siblings, 1 reply; 25+ messages in thread
From: sk @ 2003-07-28 0:21 UTC (permalink / raw)
To: comp.lang.ada
randhol+abuse@pvv.org:
> Yes, Why? Why is writing source code in one line so important?
...
I find a large nested error checking "if-then-elsif" distracting
from keeping a focus on the overall algorithm
hyrosen@mail.com:
> Why would you write it that way? If you just want
> equivalent one liners, what's wrong with
>
> if Condition1 then raise Error1; end if;
> if Condition2 then raise Error2; end if;
> ...
Hard to explain, but I find a single line "if-then"
statement more difficult to read because I find myself
visually parsing it several times just to make sure
that I am not missing anything squeezed between the
semi-colons.
For a single line, such as the current "exit-loop-when"
statement, I can parse all the information I need in one
glance.
Remember my focus is on readability which, if I recall
correctly, is a large part of maintenence, which is a
large part of the discussions for the creation of Ada
20+ years ago.
--
-------------------------------------------------
-- Merge vertically for real address
--
-- s n p @ t . o
-- k i e k c c m
-------------------------------------------------
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Ada 0x, exception idea ?
[not found] <3F229597.3090909@myob.com>
` (2 preceding siblings ...)
2003-07-28 0:21 ` sk
@ 2003-07-28 11:24 ` sk
3 siblings, 0 replies; 25+ messages in thread
From: sk @ 2003-07-28 11:24 UTC (permalink / raw)
To: comp.lang.ada
strohm@airmail.net:
> Would you please clarify?
Yes, the post you were replying to suggested parsing
the string message attached to an exception to evaluate
an error code provided in the message by Raise_Exception,
hence my response of "Yuck"
wesgroleau@myrealbox.com:
> Why is the above (which works now) more "bulky" ...
After a brief play with it, I agree, the "case-and-raise"
syntax is a lot more elegent than a big "if-then-elsif".
However,
> case Error_Type'Value(Ada.Exceptions.Exception_Message(E)) is
> when 1 =>
> Handle_Error_One;
quickly wanders into the realms of the unreadable.
strohm@airmail.net:
> Observe that you get PRECISELY the same result with
> if Result = Bummer then raise Its_A_Bummer; end if;
> if Result = Darn then raise Darn_It; end if;
> if Result = Blast then raise Blast_It; end if;
Again, the issue isn't results, it is readability.
hyrosen@mail.com:
> Perhaps the OP has fallen under the allure of Perl,
Haha, whenever I run across Perl, I run away and can
happily claim no base Perl motives :-)
--
This thread has diverged ...
1) concerning the simple addition to a "raise" statement.
2) the usage of Ada.Exceptions and carrying around of
error codes.
As far as the second issue goes, I have no real concerns
one way or another.
However, for the first issue, I stand by the idea that
a conditional raise statement enhances readability.
--
PS. If you stop and think about it, the whole exception
raising and handling is "syntactic sugar" anyway. To
raise an exception, code has to be in place to detect
that a requested operation cannot complete without
breaking the boundaries/parameters/context of the
requestor.
The "raise" and subsequent handlers are a shorthand,
provided by the language, to ensure that all the
necessary checks are implemented rather than relying
on the coders diligence to implement them.
--
-------------------------------------------------
-- Merge vertically for real address
--
-- s n p @ t . o
-- k i e k c c m
-------------------------------------------------
^ permalink raw reply [flat|nested] 25+ messages in thread