Several catch blocks or one with dynamic_cast?

You should never,ever, throw pointers. Always throw values and catch by const references. It is almosr never possible to clear up a dynamically allocated exception object correctly.

You should never,ever, throw pointers. Always throw values and catch by const references. It is almosr never possible to clear up a dynamically allocated exception object correctly.To answer your question, I personally don't believe in having complex exception heirarchies.

If you need to perform conditional processing on the exception, you need to handle the exception much nearer to the throw site, where you have more contextual information, than you currently appear to be doing.

Neither of the two paragraphs answer the question... The throwing code is out of my control. – sharptooth Jun 11 '09 at 10:16 "It is almosr never possible to clear up a dynamically allocated exception object correctly" - er, why? If you catch it, surely you can deallocate it.

If you don't catch it, then yes... but then an uncaught exception will likely bring the process down, anyway. It's definitely not a good idea regardless, though. – Pavel Minaev Nov 26 '09 at 17:24.

I would prefer the second one. If you're concerned by the duplication, are you aware something called an "exception dispatcher"? If you find many places where you need to perform the same catch handling, you can stick it all in one function and call this function from a catch(...) block.E.g.

Void fn() { try { MightThrow(); } catch (...) { ExceptionHandler(); } } void ExceptionHandler() { try { throw; } catch( FileException* e ) { if( fileException->GetErrorCode()! = FileNotFound ) { ShowMessage( e ); } delete e; } catch( GenericException* e ) { ShowMessage( e ); delete e; } } It won't stop duplication within the handlers but it will stop duplication where you need to catch the same things in different places. Edit: You must ensure the ExceptionHandler is not called when not handling an exception otherwise much badness will occur: related question.

Second option is the "best" if you rewrite it with const & ;-) I find the second much cleaner than the first one, it clearly indicates what you want.

You need virtual function to show message from your exception. This function must be member of your root hierarchy class.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions