]> granicus.if.org Git - php/commitdiff
- Two new exceptions
authorMarcus Boerger <helly@php.net>
Mon, 1 Nov 2004 17:39:59 +0000 (17:39 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 1 Nov 2004 17:39:59 +0000 (17:39 +0000)
- Make use of new exception classes

ext/spl/php_spl.c
ext/spl/spl.php
ext/spl/spl_exceptions.c
ext/spl/spl_exceptions.h
ext/spl/spl_iterators.c

index 9bb4834e49093651329e6e75f71e4363d7194056..2486f8d3bb10c56b4d3a2cec2dc52346209a7460 100755 (executable)
@@ -166,6 +166,7 @@ PHP_FUNCTION(class_implements)
        SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \
+       SPL_ADD_CLASS(BadFunctionCallException, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(CachingRecursiveIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(Countable, z_list, sub, allow, ce_flags); \
index 027bf25a20f0bb33fef2e82562b7edb46be3b551..5f5d721b721e516171ad9a06821fdea301ac3364 100755 (executable)
@@ -145,6 +145,20 @@ class LogicException extends Exception
 {
 }
 
+/** @ingroup SPL
+ * @brief Exception thrown when a function call was illegal.
+ */
+class BadFunctionCallException extends LogicException
+{
+}
+
+/** @ingroup SPL
+ * @brief Exception thrown when a method call was illegal.
+ */
+class BadMethodCallException extends BadFunctionCallException
+{
+}
+
 /** @ingroup SPL
  * @brief Exception that denotes a value not in the valid domain was used.
  *
index 9d19962cc0a6c2f77b909b1a2e1a8504ccca258c..afd7536de5bc6e18c721e6bb7caa3efee821ca4b 100755 (executable)
@@ -34,6 +34,8 @@
 #include "spl_exceptions.h"
 
 zend_class_entry *spl_ce_LogicException;
+zend_class_entry *spl_ce_BadFunctionCallException;
+zend_class_entry *spl_ce_BadMethodCallException;
 zend_class_entry *spl_ce_DomainException;
 zend_class_entry *spl_ce_InvalidArgumentException;
 zend_class_entry *spl_ce_LengthException;
@@ -50,6 +52,8 @@ zend_class_entry *spl_ce_UnderflowException;
 PHP_MINIT_FUNCTION(spl_exceptions)
 {
     REGISTER_SPL_SUB_CLASS_EX(LogicException,           Exception,        NULL, NULL);
+    REGISTER_SPL_SUB_CLASS_EX(BadFunctionCallException, LogicException,   NULL, NULL);
+    REGISTER_SPL_SUB_CLASS_EX(BadMethodCallException,   BadFunctionCallException,   NULL, NULL);
     REGISTER_SPL_SUB_CLASS_EX(DomainException,          LogicException,   NULL, NULL);
     REGISTER_SPL_SUB_CLASS_EX(InvalidArgumentException, LogicException,   NULL, NULL);
     REGISTER_SPL_SUB_CLASS_EX(LengthException,          LogicException,   NULL, NULL);
index 1b6a7feb5b6e5beb0964a2342e44d1344d814fb8..752c988f6a13f882d531bf212ed8b6d9e8e043d8 100755 (executable)
@@ -25,6 +25,8 @@
 #include "php_spl.h"
 
 extern zend_class_entry *spl_ce_LogicException;
+extern zend_class_entry *spl_ce_BadFunctionCallException;
+extern zend_class_entry *spl_ce_BadMethodCallException;
 extern zend_class_entry *spl_ce_DomainException;
 extern zend_class_entry *spl_ce_InvalidArgumentException;
 extern zend_class_entry *spl_ce_LengthException;
index e270657ceaa21c046e1ae2a0bd4d6127f0996dc3..0be7ed61a1cf3dfe4f245d016696e969ac53cc24 100755 (executable)
@@ -34,6 +34,7 @@
 #include "spl_iterators.h"
 #include "spl_directory.h"
 #include "spl_array.h"
+#include "spl_exceptions.h"
 
 #define INLINE inline
 
@@ -244,7 +245,7 @@ next_step:
                                        if (child) {
                                                zval_ptr_dtor(&child);
                                        }
-                                       zend_throw_exception(zend_exception_get_default(), "Objects returned by RecursiveIterator::getChildren() must implement RecursiveIterator", 0 TSRMLS_CC);
+                                       zend_throw_exception(spl_ce_InvalidArgumentException, "Objects returned by RecursiveIterator::getChildren() must implement RecursiveIterator", 0 TSRMLS_CC);
                                        return;
                                }
                                if (object->mode == RIT_CHILD_FIRST) {
@@ -612,12 +613,12 @@ static INLINE spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAME
                        }
                        if (intern->u.limit.offset < 0) {
                                php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
-                               zend_throw_exception(zend_exception_get_default(), "Parameter offset must be > 0", 0 TSRMLS_CC);
+                               zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be > 0", 0 TSRMLS_CC);
                                return NULL;
                        }
                        if (intern->u.limit.count < 0 && intern->u.limit.count != -1) {
                                php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
-                               zend_throw_exception(zend_exception_get_default(), "Parameter count must either be -1 or a value greater than or equal 0", 0 TSRMLS_CC);
+                               zend_throw_exception(spl_ce_OutOfRangeException, "Parameter count must either be -1 or a value greater than or equal 0", 0 TSRMLS_CC);
                                return NULL;
                        }
                        break;
@@ -1041,11 +1042,11 @@ static INLINE void spl_limit_it_seek(spl_dual_it_object *intern, long pos TSRMLS
 
        spl_dual_it_free(intern TSRMLS_CC);
        if (pos < intern->u.limit.offset) {
-               zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "Cannot seek to %ld which is below the offset %ld", pos, intern->u.limit.offset);
+               zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Cannot seek to %ld which is below the offset %ld", pos, intern->u.limit.offset);
                return;
        }
        if (pos > intern->u.limit.offset + intern->u.limit.count && intern->u.limit.count != -1) {
-               zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "Cannot seek to %ld which is behind offest %ld plus count %ld", pos, intern->u.limit.offset, intern->u.limit.count);
+               zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Cannot seek to %ld which is behind offest %ld plus count %ld", pos, intern->u.limit.offset, intern->u.limit.count);
                return;
        }
        if (instanceof_function(intern->inner.ce, spl_ce_SeekableIterator TSRMLS_CC)) {
@@ -1325,7 +1326,7 @@ SPL_METHOD(CachingIterator, __toString)
        intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
        if (!(intern->u.caching.flags & CIT_CALL_TOSTRING))     {
-               zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "%s does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+               zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
        }
        if (intern->u.caching.zstr) {
                RETURN_STRINGL(Z_STRVAL_P(intern->u.caching.zstr), Z_STRLEN_P(intern->u.caching.zstr), 1);
@@ -1554,14 +1555,14 @@ SPL_METHOD(EmptyIterator, valid)
    Throws exception */
 SPL_METHOD(EmptyIterator, key)
 {
-       zend_throw_exception(NULL, "Accessing the key of an EmptyIterator", 0 TSRMLS_CC);
+       zend_throw_exception(spl_ce_BadMethodCallException, "Accessing the key of an EmptyIterator", 0 TSRMLS_CC);
 } /* }}} */
 
 /* {{{ proto EmptyIterator::current()
    Throws exception */
 SPL_METHOD(EmptyIterator, current)
 {
-       zend_throw_exception(NULL, "Accessing the value of an EmptyIterator", 0 TSRMLS_CC);
+       zend_throw_exception(spl_ce_BadMethodCallException, "Accessing the value of an EmptyIterator", 0 TSRMLS_CC);
 } /* }}} */
 
 /* {{{ proto EmptyIterator::next()