November 21, 2009
Chris Nicholson-Sauls wrote:
> BCS wrote:
>> Hello Jesse,
>>
>>> On Wed, 18 Nov 2009 18:27:47 -0800, Andrei Alexandrescu wrote:
>>>
>>>> Thanks! Question - is there a way to fetch the current Throwable from
>>>> within a finally clause?
>>>>
>>>> Andrei
>>>>
>>> I'm pretty sure you can't since finally isn't passed an exception. I
>>> also don't see anything in my quick search.
>>>
>>
>> That stands to reason because in some cases (when things go correctly) there isn't one.
>>
>>
> 
> One hopes.  Just the same: (hypothetical syntax incoming)
> 
> try {
>     // ...
> }
> catch ( ExceptionA exa ) {
>     // ...
> }
> catch ( ExceptionB exb ) {
>     // ...
> }
> finally ( x ) {
>     // ...
>     if ( x ) throw new ExceptionC( x );
> }
> 
> And obviously if finally has no () it doesn't bother with the feature.
> 
> -- Chris Nicholson-Sauls

I'm not that fancy. An API call getCurrentError returning an Error object or null is all that's needed. And more general too.

Andrei
November 21, 2009
Andrei Alexandrescu wrote:
> Chris Nicholson-Sauls wrote:
>> BCS wrote:
>>> Hello Jesse,
>>>
>>>> On Wed, 18 Nov 2009 18:27:47 -0800, Andrei Alexandrescu wrote:
>>>>
>>>>> Thanks! Question - is there a way to fetch the current Throwable from
>>>>> within a finally clause?
>>>>>
>>>>> Andrei
>>>>>
>>>> I'm pretty sure you can't since finally isn't passed an exception. I
>>>> also don't see anything in my quick search.
>>>>
>>>
>>> That stands to reason because in some cases (when things go correctly) there isn't one.
>>>
>>>
>>
>> One hopes.  Just the same: (hypothetical syntax incoming)
>>
>> try {
>>     // ...
>> }
>> catch ( ExceptionA exa ) {
>>     // ...
>> }
>> catch ( ExceptionB exb ) {
>>     // ...
>> }
>> finally ( x ) {
>>     // ...
>>     if ( x ) throw new ExceptionC( x );
>> }
>>
>> And obviously if finally has no () it doesn't bother with the feature.
>>
>> -- Chris Nicholson-Sauls
> 
> I'm not that fancy. An API call getCurrentError returning an Error object or null is all that's needed. And more general too.
> 
> Andrei

At which point one could argue that the constructor of Throwable or Exception could/should call that same API function itself.  I'm not strictly opposed to it, mind you, it just bodes ill not to thoroughly examine such auto-magic.

-- Chris Nicholson-Sauls
November 22, 2009
Hello Chris Nicholson-Sauls,

> BCS wrote:
> 
>> That stands to reason because in some cases (when things go
>> correctly) there isn't one.
>> 
> One hopes.  Just the same: (hypothetical syntax incoming)
> 
> try {
> // ...
> }
> catch ( ExceptionA exa ) {
> // ...
> }
> catch ( ExceptionB exb ) {
> // ...
> }
> finally ( x ) {
> // ...
> if ( x ) throw new ExceptionC( x );
> }
> And obviously if finally has no () it doesn't bother with the feature.
> 

IIRC the .NET CLI has some of what you want:

http://stackoverflow.com/questions/533968/c-finally-block-that-only-runs-on-exceptions


1 2
Next ›   Last »