Which exception

Tom tom at nospam.com
Mon Oct 30 05:56:42 PST 2006


== Quote from Frits van Bommel (fvbommel at REMwOVExCAPSs.nl)'s article
> Tom wrote:
> > Hey,
> >
> > lets say I have something like the following:
> >
> > try {
> >     // Code that throws some exception I don't know of.
> > } catch (Exception ex) {
> >     writefln(ex.classinfo.name); // works but it's not what I need
> > }
> >
> > Is there some way to get the name of the class 'ex' is instance of (the
> > derived class and not the base class)?
> I'm sorry, but what *is* it that you need if not the above?
>      import std.stdio;
>      class DerivedException : Exception { this() { super(""); } }
>      void main() {
>          try {
>              // Code that throws some exception.
>              throw new DerivedException;
>          } catch (Exception ex) {
>              writefln(ex.classinfo.name); // writes "DerivedException"
>          }
>      }
> The above code writes "DerivedException" to stdout, which is the name of
> the most derived class ex is an instance of.
> Am I missing something?

No, you're right. It works here, on a WinXP machine. When I get home later, I'll
test it on my Linux, where it didn't work. I hope it's only my mistake and not a
linux-specific bug.

Regards,
--
Tom;



More information about the Digitalmars-d mailing list