Sunday 15 June 2014

c++ - Is there an occassion where using catch all clause : catch (...) is justified? -


Every time I have caught all the statements:

  try {// some code } Hold (...) {}  

In this always has been misused

Arguments against using cache All sections Are clear This will include anything that contains OS exceptions such as Access violation, since the exception handler can not know who it is working with, in most cases the exception is ambiguous log message or some incompatible message box Will appear in the form.

then hold (...) seems natural evil

but it has still been implemented in C ++ and other languages ​​(Java, C #) applies the same technique. So in some cases it is fair use?

The argument against using cache is clear all sections, these OS exceptions such as access The violation will catch anything because the exception handler can not know what the behavior is with it, in most cases the exception will appear as a fuzzy log message or some unorganized message box.

And if those same exceptions aren

hold (...) presenting at least my self message box (And starts customizing) logging, saving crash dumps, etc. ).

I think the Destructors have proper use of hold (...). I can not throw devastators - well, I mean, they can throw, but if a district without any progress Because of the exception of the thrown during the pile, the program ends, so they should not allow the exceptions to be avoided. It is generally better that instead of ending the program, the exceptions continue to be uninterrupted first.

Another situation is in a worker thread that can work arbitrarily; Normally you do not want an unexpected accident if the worker throws an exception. The worker provides the opportunity to clamp (...) semi-cleanliness and closure in the thread.


No comments:

Post a Comment