Owen,

>While attempting to trace a bug in one of the tasks, I came across a
>'feature' of .NET exception handling: rethrowing a caught exception
>overwrites the stack trace of the original exception.

Actually, this has nothing to do with the .NET exception model, it is
just a lesser-known C# semantic. The problem is that the code is
explicitly thrown a new exception (the fact that it is an existent
exception object is irrelevant here), instead of actually rethrowing
the exception.

The correct way would be to use the 'real' rethrow operator, namely a
throw with no arguments. IOW, just replace
    throw e;
with
    throw;

in the catch clause.

For those with interest in the actual C# spec, this is discussed in
section 15.9.5 of the ECMA C# spec, which says:
"A throw statement with no expression can be used only in a catch
block, in which case, that statement re-throws the exception that is
currently being handled by that catch block."

-- 
Tomas Restrepo
[EMAIL PROTECTED]



-------------------------------------------------------
In remembrance
www.osdn.com/911/
_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to