Overloading Exception Class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Overloading Exception Class

Post 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>";
	}

}
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Overloading Exception Class

Post by requinix »

The $code has to be a long (ie, integer). If you want a different type then you'd need a different variable.
Post Reply