Topic: same catch handler twice
Author: "Claude Qu zel" <Claude_Quezel@Syntell.corba>
Date: 2000/08/03 Raw View
Is it legal in C++ to have the same catch handler twice? For example
try {
} catch(const ExceptionClass& ex) {
// ...
} catch(const ExceptionClass& ex) {
// same as previous. never executed
}
I think the code is legal. I have not found any such restrictions in the
draft standard. I do not have a copy of the final standard.The draft
metions:
"15.3 Handlers for a try block are tried in order of appearance. This
makes it possible to write handlers that can never be executed, for
example by placing a handler for a derived class after a handler for a
corresponding base class."
Someone will probably want to know why I would want to know this. Here
is the reason: This question came up in the pthreads-win32 forum because
the package defines the following catch macro::
>
> I noticed that pthread.h has a macro that defines 'catch'. (macro
> reproduced here for convenience)
>
> /*
> * Redefine the C++ catch keyword to ensure that applications
> * propagate our internal exceptions up to the library's internal
handlers.
> */
> #define catch(E) \
> catch(Pthread_exception_cancel) \
> { \
> throw; \
> } \
> catch(Pthread_exception_exit) \
> { \
> throw; \
> } \
> catch(E)
>
> This breaks the following legal C++ code (because there will be
multiple
> catch blocks for Pthread_exception_cancel and Pthread_exception_exit):
>
> try {
> // ...
> }
>
> catch ( some_exception ) { }
>
> catch ( some_other_exception ) { }
Claude
--
Claude Qu=E9zel (claude_quezel@syntell.corba)
anti-spam: replace corba by com in private replies
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]