What is throwable
Steve Teale
steve.teale at britseyeview.com
Thu Mar 19 00:19:49 PDT 2009
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?
More information about the Digitalmars-d
mailing list