Page 1 of 1

Overloading Exception Class

Posted: Sat Sep 18, 2010 7:52 pm
by Weiry
Hey all,

I am creating a custom exception class which extends the default php Exception class and overloads the __toString() function.

By default, the PHP Exception class has a defined $code variable which is an INTEGER
The error codes i am using are in the format of 6xx.x
Because the default $code is defined as an integer, all my error codes come out as 6xx
Is it possible to overload it as a double or float?

Code: Select all

<?php
/**
 * Define a custom exception class
 */
class EAPIException extends Exception{

	public function __Construct($message, $code = 0) {

		// construct the parent Exception class
		parent::__Construct($message, $code);
		
	}

	// custom string representation of object
	public function __toString() {
		return "<pre>[{$this->code}]: {$this->message}\n</pre>";
	}

}
?>

Re: Overloading Exception Class

Posted: Sun Sep 19, 2010 1:49 am
by requinix
The $code has to be a long (ie, integer). If you want a different type then you'd need a different variable.