comp.lang.ada
 help / color / mirror / Atom feed
* Ada 0x, exception idea ?
@ 2003-07-26 14:52 sk
  2003-07-26 15:53 ` John R. Strohm
  2003-07-27  9:10 ` Preben Randhol
  0 siblings, 2 replies; 25+ messages in thread
From: sk @ 2003-07-26 14:52 UTC (permalink / raw)
  To: comp.lang.ada

Hi,

IDEA

when <boolean-condition> raise <exception-name>;

OR

when <boolean-condition> then raise <exception-name>;

OR

raise <exception-name> when <boolean-condition>;

SITUATION

Call_Condition_Setting_Procedure (Paramters, Success);

if not Success then
     raise Call_Failed;
end if;


REPLACED BY

Call_Condition_Setting_Procedure (Paramters, Success);

when not Success raise Call_Failed;
OR
when not Success then raise Call_Failed;
OR
raise Call_Failed when not Success;


Thoughts ?

(This is a ghost of Timex/Sinclair Basic "ON ERR GOSUB" (sorry to
pollute with the "B" word :-)).

-- 
-------------------------------------------------
-- 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-26 14:52 Ada 0x, exception idea ? sk
@ 2003-07-26 15:53 ` John R. Strohm
  2003-07-26 17:08   ` sk
  2003-07-26 17:08   ` sk
  2003-07-27  9:10 ` Preben Randhol
  1 sibling, 2 replies; 25+ messages in thread
From: John R. Strohm @ 2003-07-26 15:53 UTC (permalink / raw)


"sk" <noname@myob.com> wrote in message
news:mailman.0.1059231120.320.comp.lang.ada@ada.eu.org...
> Hi,
>
> IDEA
>
> when <boolean-condition> raise <exception-name>;
>
> OR
>
> when <boolean-condition> then raise <exception-name>;
>
> OR
>
> raise <exception-name> when <boolean-condition>;
>
> SITUATION
>
> Call_Condition_Setting_Procedure (Paramters, Success);
>
> if not Success then
>      raise Call_Failed;
> end if;
>
>
> REPLACED BY
>
> Call_Condition_Setting_Procedure (Paramters, Success);
>
> when not Success raise Call_Failed;
> OR
> when not Success then raise Call_Failed;
> OR
> raise Call_Failed when not Success;
>
>
> Thoughts ?
>
> (This is a ghost of Timex/Sinclair Basic "ON ERR GOSUB" (sorry to
> pollute with the "B" word :-)).

Bletch.

As you observe, your proposed constructs are precisely equivalent to

    call_procedure(..., success);
    if not success then
      raise call_failed;
    end if;

Ada in general does not bother with unnecessary syntactic sugar, which is
what this is.

Second, and more general: If an exception should be raised SOME of the time
when the procedure fails, it probably should be raised ALL of the time, and
then the procedure itself should raise the exception, not set a status flag
and rely on the caller to check the flag and raise the exception if
necessary.

Observe that raising the exception inside the procedure is more robust: it
REQUIRES every caller to be prepared to trap the exception, and hence handle
a potential error case.  (One of the more common errors made by C
programmers is forgetting to check a pass/fail status return parameter.)





^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Ada 0x, exception idea ?
  2003-07-26 15:53 ` John R. Strohm
@ 2003-07-26 17:08   ` sk
  2003-07-26 17:08   ` sk
  1 sibling, 0 replies; 25+ messages in thread
From: sk @ 2003-07-26 17:08 UTC (permalink / raw)
  To: comp.lang.ada


-- 
-------------------------------------------------
-- 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-26 15:53 ` John R. Strohm
  2003-07-26 17:08   ` sk
@ 2003-07-26 17:08   ` sk
  2003-07-27  2:46     ` Wesley Groleau
  2003-07-27 16:35     ` Hyman Rosen
  1 sibling, 2 replies; 25+ messages in thread
From: sk @ 2003-07-26 17:08 UTC (permalink / raw)
  To: comp.lang.ada

 > Bletch.
 >
 > As you observe, your proposed constructs are precisely equivalent to
 >
 >    call_procedure(..., success);
 >    if not success then
 >      raise call_failed;
 >    end if;
 >
 >Ada in general does not bother with unnecessary syntactic sugar,
 > which is what this is.

... and as a "generalization", that is a dubious position.

For as long as I can remember, Ada IS ABOUT MAINTAINENCE, which is
about using "syntatic sugar" to make things absolutely clear.

READABILITY

raise Call_Error1 when Condition1;
raise Call_Error2 when Condition2;
raise Call_Error3 when Condition3;
raise Call_Error4 when Condition4;
raise Call_Error5 when Condition5;

... is lot more readable than and equivalent ...

if Condition1 then
     raise Error1;
elsif Condition2  then
     raise Error2;
elsif Condition3  then
     raise Error3;
elsif Condition4  then
     raise Error4;
elsif Condition5 then
     raise Error5;
...

 > ... procedure itself should raise the exception, not set a status
 > flag ...

How nice for you to live in a purely Ada world :-)

The mostly "C" world I live in, where I have to interface Ada to the
underlying operating environment, almost always uses a return code
of some kind.

-- 
-------------------------------------------------
-- 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-26 17:08   ` sk
@ 2003-07-27  2:46     ` Wesley Groleau
  2003-07-27 16:35     ` Hyman Rosen
  1 sibling, 0 replies; 25+ messages in thread
From: Wesley Groleau @ 2003-07-27  2:46 UTC (permalink / raw)



> The mostly "C" world I live in, where I have to interface Ada to the
> underlying operating environment, almost always uses a return code
> of some kind.

Legal Ada 95 example:

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;

.......

Ada 95 does have

    exit <loopname> when <condition>;

and some folks thought

    raise <exception> when <condition>;

should be there as well.  But it was rejected.




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Ada 0x, exception idea ?
  2003-07-26 14:52 Ada 0x, exception idea ? sk
  2003-07-26 15:53 ` John R. Strohm
@ 2003-07-27  9:10 ` Preben Randhol
  1 sibling, 0 replies; 25+ messages in thread
From: Preben Randhol @ 2003-07-27  9:10 UTC (permalink / raw)


sk wrote:
> Thoughts ?

Yes, Why? Why is writing source code in one line so important?

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



^ 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 ` 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 ` 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 ?
       [not found] <3F229597.3090909@myob.com>
  2003-07-27 11:42 ` 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-26 17:08   ` sk
  2003-07-27  2:46     ` Wesley Groleau
@ 2003-07-27 16:35     ` Hyman Rosen
  1 sibling, 0 replies; 25+ messages in thread
From: Hyman Rosen @ 2003-07-27 16:35 UTC (permalink / raw)


sk wrote:
> raise Call_Error1 when Condition1;
> raise Call_Error2 when Condition2;
> ... is lot more readable than and equivalent ...
> if Condition1 then
>     raise Error1;
> elsif Condition2  then
>     raise Error2;
> ...

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;
...




^ 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 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 ?
       [not found] <3F229597.3090909@myob.com>
  2003-07-27 11:42 ` 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 ?
  2003-07-27 11:42 ` 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: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: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 ?
  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 ?
  2003-07-28  2:46     ` John R. Strohm
@ 2003-07-28  3:23       ` Hyman Rosen
  2003-07-28  3:24       ` Hyman Rosen
  1 sibling, 0 replies; 25+ messages in thread
From: Hyman Rosen @ 2003-07-28  3:23 UTC (permalink / raw)


John R. Strohm wrote:
> Observe that you get PRECISELY the same result

Perhaps the OP has fallen under the allure of Perl,
which allows conditionals to be tagged onto the end
of statements -
     print "$k = $args{$k}\n" unless $k eq "password";

(That's a line of code I just wrote - or rather, amended -
last week. To add the password check. So that it wouldn't
e-mail the password to the whole company. Sigh.)




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Ada 0x, exception idea ?
  2003-07-28  2:46     ` John R. Strohm
  2003-07-28  3:23       ` Hyman Rosen
@ 2003-07-28  3:24       ` Hyman Rosen
  1 sibling, 0 replies; 25+ messages in thread
From: Hyman Rosen @ 2003-07-28  3:24 UTC (permalink / raw)


John R. Strohm wrote:
> Observe that you get PRECISELY the same result

Oh, and by the way, I posted the same bit of code.
But I think I'm in your kill file :-)




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Ada 0x, exception idea ?
  2003-07-28  0:21 ` sk
@ 2003-07-28  8:38   ` Preben Randhol
  0 siblings, 0 replies; 25+ messages in thread
From: Preben Randhol @ 2003-07-28  8:38 UTC (permalink / raw)


sk wrote:
> 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

I find that hard to believe. Why would you need a large nested error
checking? And how would you manage to get away from the nesting with the
raise ... when ?

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



^ 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

* 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

end of thread, other threads:[~2003-07-28 12:41 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-26 14:52 Ada 0x, exception idea ? sk
2003-07-26 15:53 ` John R. Strohm
2003-07-26 17:08   ` sk
2003-07-26 17:08   ` sk
2003-07-27  2:46     ` Wesley Groleau
2003-07-27 16:35     ` Hyman Rosen
2003-07-27  9:10 ` Preben Randhol
     [not found] <3F229597.3090909@myob.com>
2003-07-27 11:42 ` sk
2003-07-27 15:33   ` Nick Roberts
2003-07-27 17:13     ` Samuel Tardieu
2003-07-28 12:41       ` Nick Roberts
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
2003-07-27 15:51 ` sk
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
2003-07-28  0:27       ` Wesley Groleau
2003-07-28  2:50       ` John R. Strohm
2003-07-28  0:21 ` sk
2003-07-28  8:38   ` Preben Randhol
2003-07-28 11:24 ` sk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox