The language reference says:

Throw Statement
Throw an exception.

ThrowStatement:
        throw Expression ;

Expression is evaluated and must be an Object reference. The Object reference 
is thrown as an exception.

But the following compiles and runs and catches the RottenEgg.


import std.stdio;

class RottenEgg
{
   string message;
   this(string s) { message = s; }
}

void main()
{
   try
   {
      throw new RottenEgg("something smelly");
   }
   catch (Exception e)
   {
      writefln("Caught exception ", e.toString()); 
   }
   catch (RottenEgg err)
   {
      writefln("Caught RottenEgg exception ", err.message);
   }
}

What is the point of class Throwable if you can throw any old class object?

Reply via email to