as an example of what I want to do, in C# you can do this:
does C++ have a mechanism like this whereby I can allow the same exception to continue propagating upwards, but handle it at more than one level of the call chain?
catch (Exception e)
// do something with exception
throw; // continues propagating the exception without resetting the stack trace
Yes. It does. It is almost identical in C++. The primary difference (I'm guessing as I don't know exactly how it works in C#.) is that in C++ the `catch' variable should always be a reference (&).
That said, please don't do this. It is a sign of misunderstanding how exceptions best work.
What are you trying to accomplish?
Saying "handle it at more than one level" is not sufficient as that statement is flawed. If you handle an exception at one level it has no business being propagated higher as it has already been handled.
If you need to transform an exception because the error has been handled at a level where the existence of the error signals an entirely different form of failure a different exception should be thrown.
If you need to add context to an exception, your exception class and point of origin are probably flawed. This can be overlooked if you need to add context to the exception at a higher level because lower level facilities aren't controlled by you.
If you need to handle a particular flavor of exception by inspecting the attributes of an instance of the exception class you do not have enough exception classes to do the job. The point of the `catch' variable is so that one might handle exactly that error condition. In general, you can assume that one class for each flavor of exception is correct.
it's not that I have a specific purpose in mind, or that I'm trying to accomplish anything. I recently learned about this feature of C#, and I was just curious to know if it also worked in C++.
As phantomotap said, never catch exceptions by value. Always catch them by const reference or you may run into slicing issues (google C++ slicing if you don't know what that means). Anyhow, to rethrow the exception that is currently being handled, a simple
the example I gave was in C#, so it catches by reference. in C++ I know to always catch by reference.
Ok sorry, didn't read the thread carefully enough.