exception handling

9 messages Options
Embed this post
Permalink
helmut.brandl

exception handling

Reply Threaded More More options
Print post
Permalink
Dear ES team,

there are currently 2 interfaces for handling exceptions: the class
EXCEPTIONS and EXCEPTION_HANDLER. They offer overlapping functions. But
each one has features which the other doesn't have.

Which one shall I use to be future proof? I guess it is EXCEPTION_HANDLER.

Helmut
helmut.brandl

Re: exception handling

Reply Threaded More More options
Print post
Permalink
Sorry for the typo. I meant EXCEPTION_MANAGER and not EXCEPTION_HANDER.

Helmut Brandl wrote:

> Dear ES team,
>
> there are currently 2 interfaces for handling exceptions: the class
> EXCEPTIONS and EXCEPTION_HANDLER. They offer overlapping functions. But
> each one has features which the other doesn't have.
>
> Which one shall I use to be future proof? I guess it is EXCEPTION_HANDLER.
>
> Helmut
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
Emmanuel Stapf

RE: exception handling

Reply Threaded More More options
Print post
Permalink
EXCEPTIONS if for backward compatibility and EXCEPTION_MANAGER is the class to use
if you want to get information about a current exception.

Manu

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Helmut Brandl
> Sent: Wednesday, June 17, 2009 8:05 AM
> To: [hidden email]
> Subject: Re: [eiffel_software] exception handling
>
> Sorry for the typo. I meant EXCEPTION_MANAGER and not EXCEPTION_HANDER.
>
> Helmut Brandl wrote:
> > Dear ES team,
> >
> > there are currently 2 interfaces for handling exceptions: the class
> > EXCEPTIONS and EXCEPTION_HANDLER. They offer overlapping functions. But
> > each one has features which the other doesn't have.
> >
> > Which one shall I use to be future proof? I guess it is
> EXCEPTION_HANDLER.
> >
> > Helmut
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------  
helmut.brandl

Re: exception handling

Reply Threaded More More options
Print post
Permalink
Is it possible to get an additional feature in EXCEPTION_MANAGER?

If I want to handle an exception, I usually want to handle the original
exception and not the last exception (which is in most cases just
ROUTINE_FAILURE unless the exception is handled by exactly the same
procedure as the one which throws the exception). I know I can get that by

  last_exception.origin

But since this is the majority of all cases, I would prefer to get that by

  original_exception   -- or just `exception'

I can hardly imagine that the current exception is of any interest. But
the original exception is always needed, if you want to handle the
exception and react to different types of exceptions.


Regards
Helmut


Emmanuel Stapf [ES] wrote:

> EXCEPTIONS if for backward compatibility and EXCEPTION_MANAGER is the class to use
> if you want to get information about a current exception.
>
> Manu
>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of Helmut Brandl
>> Sent: Wednesday, June 17, 2009 8:05 AM
>> To: [hidden email]
>> Subject: Re: [eiffel_software] exception handling
>>
>> Sorry for the typo. I meant EXCEPTION_MANAGER and not EXCEPTION_HANDER.
>>
>> Helmut Brandl wrote:
>>> Dear ES team,
>>>
>>> there are currently 2 interfaces for handling exceptions: the class
>>> EXCEPTIONS and EXCEPTION_HANDLER. They offer overlapping functions. But
>>> each one has features which the other doesn't have.
>>>
>>> Which one shall I use to be future proof? I guess it is
>> EXCEPTION_HANDLER.
>>> Helmut
>>>
>>>
>>> ------------------------------------
>>>
>>> Yahoo! Groups Links
>>>
>>>
>>>
>>
>> ------------------------------------
>>
>> Yahoo! Groups Links
>>
>>
>>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
jimelihel

Re: exception handling

Reply Threaded More More options
Print post
Permalink
In reply to this post by helmut.brandl
Can someone clarify something about exception philosophy in Eiffel?

My understanding was, that if you let an exception propagate outside the
routine in which it occurred, you'd be sending information that is very
likely of no use to the caller, since it is not part of the failed
routine's contract.

Have I got that right? Is it too extreme of an attitude to be practical?

- Jim Heliotis

Emmanuel Stapf

RE: Re: exception handling

Reply Threaded More More options
Print post
Permalink
> Can someone clarify something about exception philosophy in Eiffel?
>
> My understanding was, that if you let an exception propagate outside the
> routine in which it occurred, you'd be sending information that is very
> likely of no use to the caller, since it is not part of the failed
> routine's contract.
>
> Have I got that right? Is it too extreme of an attitude to be practical?

This is exactly the Eiffel philosophy. The caller will get a ROUTINE_FAILURE
exception and if the caller really wants more details, then it can access the
original exception.

In practice, the original exception is good to have for submitting a bug report to
the owner of the code that fails.

Regards,
Manu

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------  
helmut.brandl

Re: Re: exception handling

Reply Threaded More More options
Print post
Permalink
Emmanuel Stapf [ES] wrote:

>> Can someone clarify something about exception philosophy in Eiffel?
>>
>> My understanding was, that if you let an exception propagate outside the
>> routine in which it occurred, you'd be sending information that is very
>> likely of no use to the caller, since it is not part of the failed
>> routine's contract.
>>
>> Have I got that right? Is it too extreme of an attitude to be practical?
>
> This is exactly the Eiffel philosophy. The caller will get a ROUTINE_FAILURE
> exception and if the caller really wants more details, then it can access the
> original exception.
>
> In practice, the original exception is good to have for submitting a bug report to
> the owner of the code that fails.
>

Manu,

no question about what you have said. But the point I wanted to make is
different.

If an exception is thrown, a corresponding rescue clause (if available)
is entered. If a rescue clause has been entered, you know already that a
ROUTINE_FAILURE has been thrown. Therefore having access to an exception
object of type ROUTINE_FAILURE doesn't give you additional information.

If the rescue clause can handle the exception (i.e. reestablish the
class invariant and retry or fail) without access to an exception
object, it is fine. But if it needs information about the exception
being thrown, it usually needs the original exception.

So my point was ergonomic: Why access the original exception object via
another exception object which is useless instead of having access to
the exception object of the original exception directly?

It would be interesting to get feedback if my thinking above is wrong or
if others had already made the same experience. Has anybody else already
used information in the ROUTINE_FAILURE exception object?


Regards
Helmut
Emmanuel Stapf

RE: Re: exception handling

Reply Threaded More More options
Print post
Permalink
As you sai, for me, a rescue clause is meant to restore the invariant in case it
did not hold anymore and to perform some cleanup. The only place I use the
original exception is to actually log something that will be useful for the owner
of the code that failed.

Adding a convenience routine when the code is complex usually makes sense, but I'm
not sure the extra indirection for accessing the original exception requires it.

Regards,
Manu

------------------------------------------------------------------------  
Eiffel Software
805-685-1006
http://www.eiffel.com       
Customer support: http://support.eiffel.com       
User group: http://groups.eiffel.com/join       
------------------------------------------------------------------------  
helmut.brandl

Re: Re: exception handling

Reply Threaded More More options
Print post
Permalink
Emmanuel Stapf [ES] wrote:
> As you said, for me, a rescue clause is meant to restore the invariant in case it
> did not hold anymore and to perform some cleanup. The only place I use the
> original exception is to actually log something that will be useful for the owner
> of the code that failed.


Ok, so we agree, that the original exception might be useful in some
cases. But have you had up to now any use of the `last_exception' which
is usually just an intermediate ROUTINE_FAILURE?

If there is one, I would be interested to learn such a case. I have not
yet found any.

Helmut


>
> Adding a convenience routine when the code is complex usually makes sense, but I'm
> not sure the extra indirection for accessing the original exception requires it.
>
> Regards,
> Manu
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>