Skip to content

Commit d60c43e

Browse files
committed
Convert exception instanceof checks to assertions
1 parent edf2296 commit d60c43e

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Zend/zend_exceptions.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo
9292
return;
9393
}
9494

95+
ZEND_ASSERT(instanceof_function(add_previous->ce, zend_ce_throwable)
96+
&& "Previous execption must implement Throwable");
97+
9598
ZVAL_OBJ(&pv, add_previous);
96-
if (!instanceof_function(Z_OBJCE(pv), zend_ce_throwable)) {
97-
zend_error_noreturn(E_CORE_ERROR, "Previous exception must implement Throwable");
98-
return;
99-
}
10099
ZVAL_OBJ(&zv, exception);
101100
ex = &zv;
102101
do {
@@ -837,16 +836,14 @@ static zend_object *zend_throw_exception_zstr(zend_class_entry *exception_ce, ze
837836
{
838837
zval ex, tmp;
839838

840-
if (exception_ce) {
841-
if (!instanceof_function(exception_ce, zend_ce_throwable)) {
842-
zend_error(E_NOTICE, "Exceptions must implement Throwable");
843-
exception_ce = zend_ce_exception;
844-
}
845-
} else {
839+
if (!exception_ce) {
846840
exception_ce = zend_ce_exception;
847841
}
848-
object_init_ex(&ex, exception_ce);
849842

843+
ZEND_ASSERT(instanceof_function(exception_ce, zend_ce_throwable)
844+
&& "Exceptions must implement Throwable");
845+
846+
object_init_ex(&ex, exception_ce);
850847

851848
if (message) {
852849
ZVAL_STR(&tmp, message);

0 commit comments

Comments
 (0)