Prev | Current Page 368 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

PosInfos;
public function new( desc : String, ?info : haxe.PosInfos ) : Void
{
this.__description = desc;
this.__info = info;
}
private function getDescription() : String
{
var msg : String = ???Class : ??? + this.__info.className + ??? - > ???;
msg += this.__info.methodName + ???()\nline ???;
msg += this.__info.lineNumber + ??? : ??? + this.__description;
return msg;
}
}
190
Part I: The Core Language
Now, you ??™ ll require a class that extends the base error class.
import GenericError;
class ObjectNotInstantiated extends GenericError
{
public function new( ?info : haxe.PosInfos )
{
super( ???Item is not an instance of an object??? );
}
}
That ??™ s all you need for the error classes. How about a test class to run your little experiment?
import GenericError;
import ObjectNotInstantiated;
class ErrorObjectTest
{
public static function main()
{
try
{
throw new ObjectNotInstantiated();
}
catch( err : ObjectNotInstantiated )
{
trace( ???Not an instance: ??? + err.message );
}
catch( err : GenericError )
{
trace( ???Generic: ??? + err.


Pages:
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380