# New SPL exceptions proposal

- Thread: https://externals.io/message/41855
- Original archive: https://news-web.php.net/php.internals/41855
- Started by David Grudl on 2008-11-11T16:16:37+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #41855 — David Grudl — 2008-11-11T16:16:37+00:00

URL: https://externals.io/message/41855#41855

Hello *internals* and Marcus!

What do you think about possibility to implement to PHP 5.3 several 
useful default exceptions?

(note that InvalidArgumentException, RuntimeException and LogicException 
exists since PHP 5.1)

/**
 * The exception that is thrown when the value of an argument is
 * outside the allowable range of values as defined by the invoked method.
*/
class ArgumentOutOfRangeException extends InvalidArgumentException
{}

/**
 * The exception that is thrown when a method call is invalid for the 
object's
 * current state, method has been invoked at an illegal or inappropriate 
time.
*/
class InvalidStateException extends RuntimeException
{}

/**
 * The exception that is thrown when a requested method or operation is 
not implemented.
 */
class NotImplementedException extends LogicException
{}

/**
 * The exception that is thrown when a requested method or operation is 
deprecated.
*/
class DeprecatedException extends LogicException
{}

/**
 * The exception that is thrown when an invoked method is not supported. 
For scenarios where
 * it is sometimes possible to perform the requested operation, see 
InvalidStateException.
 */
class NotSupportedException extends LogicException
{}

/**
 * The exception that is thrown when an I/O error occurs.
 */
class IOException extends RuntimeException
{}

/**
 * The exception that is thrown when accessing a file that does not 
exist on disk.
 */
class FileNotFoundException extends IOException
{}

/**
 * The exception that is thrown when part of a file or directory cannot 
be found.
 */
class DirectoryNotFoundException extends IOException
{}


And the last one (this is something like BadMethodException, but for 
properties)

/**
 * The exception that is thrown when accessing a class member (property 
or method) fails.
 */
class MemberAccessException extends LogicException
{}


David Grudl

---

## #41857 — Etienne Kneuss — 2008-11-11T22:00:34+00:00

URL: https://externals.io/message/41855#41857 · In reply to: #41855

Hello David,


> Hello *internals* and Marcus!
>
> What do you think about possibility to implement to PHP 5.3 several useful
> default exceptions?
>
> (note that InvalidArgumentException, RuntimeException and LogicException
> exists since PHP 5.1)
>
> /**
> * The exception that is thrown when the value of an argument is
> * outside the allowable range of values as defined by the invoked method.
> */
> class ArgumentOutOfRangeException extends InvalidArgumentException
> {}

Looks a bit redundant with OutOfRangeException

>
> /**
> * The exception that is thrown when a method call is invalid for the
> object's
> * current state, method has been invoked at an illegal or inappropriate
> time.
> */
> class InvalidStateException extends RuntimeException
> {}
>
> /**
> * The exception that is thrown when a requested method or operation is not
> implemented.
> */
> class NotImplementedException extends LogicException
> {}
>
> /**
> * The exception that is thrown when a requested method or operation is
> deprecated.
> */
> class DeprecatedException extends LogicException
> {}
>
> /**
> * The exception that is thrown when an invoked method is not supported. For
> scenarios where
> * it is sometimes possible to perform the requested operation, see
> InvalidStateException.
> */
> class NotSupportedException extends LogicException
> {}
>
> /**
> * The exception that is thrown when an I/O error occurs.
> */
> class IOException extends RuntimeException
> {}
>
> /**
> * The exception that is thrown when accessing a file that does not exist on
> disk.
> */
> class FileNotFoundException extends IOException
> {}
>
> /**
> * The exception that is thrown when part of a file or directory cannot be
> found.
> */
> class DirectoryNotFoundException extends IOException
> {}
>
>
> And the last one (this is something like BadMethodException, but for
> properties)
>
> /**
> * The exception that is thrown when accessing a class member (property or
> method) fails.
> */
> class MemberAccessException extends LogicException
> {}
>

The main problem about adding such classes is that it may/will break
BC, so for one they will have to be renamed Spl*Exception.
Additionally, there is little point in defining these exceptions if we
don't use them internally, and afaik SPL wouldn't need all of them.
On the other hand, we still have lot or generic RuntimeExceptions [1],
we might want to use more specific classes for them but I believe the
currently available exceptions will suffice in most cases.

Regards


1:
colder@larry ~/cvs/php-src $ fgrep -r "zend_throw_exception"
ext/spl/*.c | php -R 'preg_match("/spl_ce_(\w+)/", $argn, $match);
echo $match[1]."\n";' | sort | uniq -c
     12 BadMethodCallException
      1 DomainException
     17 InvalidArgumentException
     12 LogicException
      3 OutOfBoundsException
     10 OutOfRangeException
     40 RuntimeException
      7 UnexpectedValueException

>
> David Grudl
>
> --
> 
> 
>
>
>



-- 
Etienne Kneuss
http://www.colder.ch

Men never do evil so completely and cheerfully as
when they do it from a religious conviction.
-- Pascal

---

## #41864 — Hannes Magnusson — 2008-11-12T07:28:46+00:00

URL: https://externals.io/message/41855#41864 · In reply to: #41857

> Hello David,
>
> 
> > […]
>
> Looks a bit redundant with OutOfRangeException


I see no point in any of them.
We already have like 15 exceptions.. There is absolutely no point in
any more, unless they'll have some superpowers (like ErrorException).

-Hannes
