Re: Common exception handling



On Aug 29, 1:32 am, Martin <martin.do...@xxxxxxxxxxxxxxx> wrote:
On 26 Aug, 15:43, Adam Beneschan <a...@xxxxxxxxxx> 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;

-- Adam

Surely you missed a smiley off this suggestion!!! :-)

Well, I do often post silly things without smileys and assume everyone
is astute enough to figure out that I was trying to be funny. But I
wasn't being funny here. Although the above looks somewhat ugly, I
can imagine that a solution of this sort may be entirely appropriate
in some cases. Suppose, for example, that the common code isn't just
at the beginning, but is also at the end, or maybe even in the middle;
the nested exception handler/reraise solution might not be so clean in
that case. Another problem with the nested exception handler solution
is that it could incur extra overhead since exception raising isn't
necessarily cheap. That shouldn't matter in most cases, but sometimes
it might. So I don't understand why the above is so ridiculous as to
merit the comment you gave.

I would say, though, that if your exception-handling code gets that
complex, it might be time to think about declaring just one exception
and a separate data structure for passing additional exception info
around.

-- Adam

.



Relevant Pages

  • Re: C# Compiler Options
    ... even though the resource file has been embedded. ... The exception that I receive is: ... "WindowsApplication2". ... > MVP Carlos's suggestion should work: ...
    (microsoft.public.vsnet.ide)
  • Re: rebulid master db
    ... My suggestion is to contact Microsoft Support Services. ... "The State of your SQL Server Installation was not changed after the setup ... The following is an exception stack listing the exceptions in outermost to ...
    (microsoft.public.sqlserver.server)
  • Re: Deleting Attachments
    ... With the exception of saving the attachment as you suggested below (because ... the file was already stored on her harddrive) I followed your suggestion but ... The only way it really gets rid of the file, regardless of whether you save ...
    (microsoft.public.outlook)
  • Re: How to abort an install in an installer class
    ... I think Lloyd's suggestion is to try...catch.... ... there is any error occur, the exception will catch in the catch block, and ... This posting is provided "AS IS" with no warranties, ...
    (microsoft.public.dotnet.framework)
  • Re: This application has requested the Runtime to terminate it in an unusual way
    ... Thanks for suggestion .I am new to vc++ .I will my code according to ... Now i am getting runtime exception on debug mode if my internet ... Unhandled exception at 0x7c81eb33 in LiveSupport.exe: ... pszFmt, args); ...
    (microsoft.public.vc.mfc)