You are here: RE: [PHP] Including class of Exception in exception message « PHP « IT news, forums, messages
RE: [PHP] Including class of Exception in exception message

Posted by Jared Williams on 04/09/05 18:48

> I'm using Exceptions and variously handling them in
> try..catch blocks or defaulting to my set_exception_handler handler.
> When I create an Exception I'd like to prepend the class of
> the Exception to the message. Can this be done with code or
> do I have to hard code the name of the Exception class into
> the message every time I throw the exception?
>
> For Example:
>
> I'd like to turn this...
>
> throw new myException("myException: So this is it, we're
> going to die");
>
> into...
>
> throw new myException( CODE . ": So this is it, we're going to die");
>
> where CODE is some php code that refers to the class of the
> exception being thrown.
>

Subclass exception, and do it in there?

class myException extends Exception
{
function __construct($message) { parent::__construct(get_class($this).$message); }
}

class AnotherException extends myException
{
}

Jared

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация