summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2004-11-01 17:39:59 +0000
committerMarcus Boerger <helly@php.net>2004-11-01 17:39:59 +0000
commitbd40510b62d0d63a16b120a2ef102742967335d7 (patch)
tree7b03d6b811e4b445ecc02fa6df731242b7ef923d
parent623f564abc5d7165c4cfadadb7f8a98ce33ee857 (diff)
downloadphp-git-bd40510b62d0d63a16b120a2ef102742967335d7.tar.gz
- Two new exceptions
- Make use of new exception classes
-rwxr-xr-xext/spl/php_spl.c1
-rwxr-xr-xext/spl/spl.php14
-rwxr-xr-xext/spl/spl_exceptions.c4
-rwxr-xr-xext/spl/spl_exceptions.h2
-rwxr-xr-xext/spl/spl_iterators.c17
5 files changed, 30 insertions, 8 deletions
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index 9bb4834e49..2486f8d3bb 100755
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -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); \
diff --git a/ext/spl/spl.php b/ext/spl/spl.php
index 027bf25a20..5f5d721b72 100755
--- a/ext/spl/spl.php
+++ b/ext/spl/spl.php
@@ -146,6 +146,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.
*
* This kind of exception should be used to inform about domain erors in
diff --git a/ext/spl/spl_exceptions.c b/ext/spl/spl_exceptions.c
index 9d19962cc0..afd7536de5 100755
--- a/ext/spl/spl_exceptions.c
+++ b/ext/spl/spl_exceptions.c
@@ -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);
diff --git a/ext/spl/spl_exceptions.h b/ext/spl/spl_exceptions.h
index 1b6a7feb5b..752c988f6a 100755
--- a/ext/spl/spl_exceptions.h
+++ b/ext/spl/spl_exceptions.h
@@ -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;
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index e270657cea..0be7ed61a1 100755
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -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()