Class ErrorException and inheritance



Hello all,

maybe one of you can give me an answer to the following question:

Since PHP 5.3, the class \ErrorException (which extends \Exception) has
the constructor

ErrorException::__construct
(
[ string $message
[, long $code
[, long $severity
[, string $filename
[, long $lineno
[, Exception $previous = NULL
]]]]]]
)

By default, the object $e coming up with

[1] try
[2] {
[3] throw new ErrorException($message, $code, $severity);
[4] }
[5] catch (ErrorException $e)
[6] {
[7] }

has methods $e->getFile() and $e->getLine() which return the filename
resp. the line number where the exception was thrown.

Assume, you define a new class

SuperErrorException extends ErrorException,

the constructor of the subclass should at least contain the same
parameters, e.g.

namespace Super;
class SuperErrorException extends \ErrorException
{
public function __construct
(
$message = '',
$code = 0,
$severity = 0,
$filename = NULL, (A)
$lineno = NULL, (B)
Exception $previous = NULL
)
{
parent::__construct
(
$message,
$code,
$severity,
$filename,
$lineno
);
}
}

Here, $filename and $lineno are NULL by default to make the parameters
optional (as in ErrorException).

The problem:

[1] try
[2] {
[3] throw new SuperErrorException($message, $code, $severity);
[4] }
[5] catch (ErrorException $e)
[6] {
[7] }

will call SuperErrorException::__construct which overwrites the defaults
for $filename and $lineno with NULL.

Replacing $filename and $lineno in (A) and (B) by __FILE__ and __LINE__
is not the solution!

What can be done to give SuperErrorException the same core functionality
as ErrorException?

Kind regards,
Werner
.



Relevant Pages

  • Class ErrorException and inheritance
    ... [, string $filename ... [, long $lineno ... SuperErrorException extends ErrorException, ... the constructor of the subclass should at least contain the same ...
    (alt.php)
  • java.util.zip.ZipFile doesnt take InputStream as constructor
    ... I'm trying to arbitrarily pull files out of a multi-100-meg zip file. ... constructor the filename. ... constructor that takes anything but a file/filename. ... data isn't a file itself but an inputstream? ...
    (comp.lang.java.programmer)
  • Re: Quick Question on Application.Exit()
    ... > appname) is run twice. ... I have in my constructor to do a check for a ... > settings file, and if it isn't found, the application exits. ... this code doesn't check for the existance of a file, only that the filename ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: logging: local functions ==> loss of lineno
    ... #IronPython isn't run with -X:Frames. ... yield filename, f.f_lineno, co.co_name ... for filename, lineno, funcname in self.callers: ...
    (comp.lang.python)
  • Re: Quick Question on Application.Exit()
    ... I have in my constructor to do a check for a ... > settings file, and if it isn't found, the application exits. ... How sure are you that filename is really null? ... using a String explicitly set to null allows Application.Exitto be called ...
    (microsoft.public.dotnet.languages.csharp)