Re: Common exception handling
- From: Adam Beneschan <adam@xxxxxxxxxx>
- Date: Tue, 26 Aug 2008 09:49:59 -0700 (PDT)
On Aug 26, 8:10 am, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
On Tue, 26 Aug 2008 07:43:20 -0700 (PDT), Adam Beneschan wrote:
On Aug 26, 6:47 am, shaunpatter...@xxxxxxxxx wrote:
Yeah, it looks like the extra layer of exception handling is the only
way. I was hoping I could avoid that if possible.
No, I don't think it's the only way. I'm surprised no one has
suggested this:
exception
when E : others =>
Print_Test (Rec);
declare
use Ada.Exceptions;
begin
if Exception_Identity(E) = A'Identity then
... handling for A
elsif Exception_Identity(E) = B'Identity then
... handling for B
etc.
else
... handling for other exceptions you didn't expect,
... but you certainly need to aware that it could
... happen
raise; --maybe
end if;
end;
Hmm, it looks quite ugly, IMO. Exception handler (case-like) is better
structured, cleaner, and possibly more efficient.
---------
If exceptions were first-class citizens allowed in case statements then:
exception
when E : others =>
Print_Test (Rec);
case E is -- This is not Ada, alas!
when A => ...
when B => ...
when others => ...
end case;
Maybe this use of CASE should be allowed, even if we don't go all the
way and make exceptions first-class entities in other ways. What does
anyone else think... would it be a worthwhile feature to propose
adding? Or is it just too "special" (if we added this, others would
ask, well why shouldn't we allow CASE on a string, or a record, or a
container, or just expand it using some user-specified relational
operator so that we can use it for everything...)?
-- Adam
.
- Follow-Ups:
- Re: Common exception handling
- From: Dmitry A. Kazakov
- Re: Common exception handling
- References:
- Common exception handling
- From: shaunpatterson
- Re: Common exception handling
- From: shaunpatterson
- Common exception handling
- Prev by Date: Re: Common exception handling
- Next by Date: Re: Common exception handling
- Previous by thread: Re: Common exception handling
- Next by thread: Re: Common exception handling
- Index(es):
Relevant Pages
|