In unmanaged C++ the current thinking is to always catch exceptions via const reference.
I'm not that experienced with managed C++ (although I'm getting to grips with the differences) but I'm wondering, what is the best way to catch exceptions here? Would exceptions ever be caught by handle i.e.
try
{
}
catch( ExceptionType^ ex )
{
}
.. and if so, would there be any caveats?
For handling managed code exceptions, yes that's the way to do it.
However if you are using Managed C++, I imagine this is becase you have the need to interop with native code (or else you are just a masochist? sorry, I am no fan of Managed C++), in which case things are more complicated. See here for some background on mixed-mode exception handling issues.
When you throw a managed exception, then there is no way to catch it except by garbage-collected handle. Managed code has much stricter rules about what can and cannot be thrown, unlike C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With