Re: Sending exceptions across domains and threads

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Thank you David.

Just for your information. I have written a small app to test performance
implications of exceptions (including scenario with cross-domain
marshalling). It's available here:

http://www.codeproject.com/useritems/ExceptionPerformance.asp

Vagif

"David Levine" <noSpam12dlevineNNTP2@xxxxxxxxx> wrote in message
news:%234UsUpTnFHA.576@xxxxxxxxxxxxxxxxxxxxxxx
>
> "Vagif Abilov" <vagif@xxxxxxxxx> wrote in message
> news:eqinISMnFHA.3828@xxxxxxxxxxxxxxxxxxxxxxx
>> There is an excellent set of guidelines about rules to throw exceptions:
>>
>> http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx
>>
>> Two very important statements:
>>
>> Do not return error codes. Exceptions are the primary means of reporting
>> errors in frameworks.
>>
>> Do not use error codes because of concerns that exceptions might affect
>> performance negatively.
>>
>> I'd love to accept these rules. The world looks much more consistent with
>> them. But! What about multiple threads and domains?
>
> Multiple threads are not an issue. Exceptions always occur on a single
> thread, and for them to be propagated to a different thread the exception
> must be rethrown on the secondary thread. This is true whether the thread
> is bounded by a single appdomain or if the thread transitions between
> multiple appdomains.
>
>
> Error codes will always be faster then exceptions because there is far
> less overhead associated with stuffing a value into a stack location then
> with going through the full 2 phase stack walk that is incurred with an
> exception.
>
>> We have a system that needs to execute calls across different AppDomains.
>> If we replace error codes with exceptions, the performance implication
>> will be huge. Really. I know Microsoft is always trying to be ahead of
>> hardware development (which is wise). But the cost of serializing
>> exceptions is so high that we are really concerned about it. What do you
>> think?
>
> The performance hit caused by exceptions is mainly due to the stack walk
> overhead, and this will be incurred regardless of the appdomain boundary.
> The appdomain boundary presents additional issues, such as changes in the
> security context, but this is present whether you use exceptions or error
> codes. It is true that the exception must be serialized, but unless you
> are calling a method in a tight loop across the boundary the extra
> performance hit should not be significant. If this is occuring in a tight
> loop then you will have other performance problems besides that of
> exceptions. You should not use exceptions to report those types of
> errors - they are most useful when used in the low-performance code path.
>
> Bottom line: all engineering consists of trade-offs. If you are writing a
> performance intensive application, or an operating system, then you may
> need to go to extraordinary lengths to achieve your performance goals, but
> for most applications it is better to use exceptions rather then error
> codes.
>
>>
>> Vagif Abilov
>> Oslo Norway
>> vagif-at-online.no
>>
>
>


.



Relevant Pages

  • Re: Exceptions vs. Error Codes
    ... > reading through threads on the topic), but I feel compelled to start ... > propagate the error is cleaner with exceptions. ... > than error codes, when in fact, they just don't see that it is just as ... > propagate the error, assuming they are following the pattern), some ...
    (comp.lang.cpp)
  • Exceptions vs. Error Codes
    ... After reading through the existing threads, ... propagate the error is cleaner with exceptions. ... Consider this idiom when using error codes: ... Using this pattern, we avoid the appearance of a slew of if/then ...
    (comp.lang.cpp)
  • Re: Exceptions vs. Error Codes
    ... > reading through threads on the topic), but I feel compelled to start ... Constructors can produce error codes. ... A constructor can take a reference ... > propagate the error is cleaner with exceptions. ...
    (comp.lang.cpp)
  • Re: Evaluating Exceptions, Try Except and Try Finally
    ... Delphi has used exceptions since the beginning. ... > way that it returns success/failure and possibly error codes. ... Error_Is_Joined surely can't be the same as the handling of ...
    (alt.comp.lang.borland-delphi)
  • Re: Sending exceptions across domains and threads
    ... Exceptions are the primary means of reporting ... > Do not use error codes because of concerns that exceptions might affect ... The performance hit caused by exceptions is mainly due to the stack walk ... and this will be incurred regardless of the appdomain boundary. ...
    (microsoft.public.dotnet.framework.clr)