Rethrow an exception like in C++?
Jonathan M Davis
jmdavisProg at gmx.com
Thu Mar 7 23:58:20 PST 2013
On Friday, March 08, 2013 08:08:48 Rob T wrote:
> On Friday, 8 March 2013 at 06:05:02 UTC, Maxim Fomin wrote:
> > Actually no.
> >
> > class myException1 : Exception { this() { super("1"); } }
> > class myException2 : Exception { this() { super("2"); } }
>
> [...]
>
> Thanks! That solves 99% of my problem. I wasn't aware that I
> could check the derived type from a base class reference like
> that.
>
> The only remaining 1% is that I have a bit more boiler plate code
> for my catch, because I still have to always explicitly catch
> something otherwise I cannot )for example) write a function to
> get the exception and perform work on it and then rethrow.
> Instead I have to
>
> catch( Exception E )
> {
> throw dostuff( E );
> }
>
> in C++ I could do simply this
>
> catch(...)
> {
> // do stuff could get the exception on its own
> throw dostuff();
> }
Then you can clearly do something here in C++ that I don't understand, because
I have absolutely no idea how you could do anything the exception if you did
catch(...), because there's no variable to work with.
Also, seeing as how the only difference between the two examples is that in the
first case, the exception is passed to be thrown and the second it's thrown
without its name, I don't see any functional difference between the two. So, I
must be missing something here.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list