From 85f62caad270ad7ec2afd826d83d1684e5a41985 Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Fri, 2 Jan 2004 19:27:02 +0000 Subject: [PATCH] Do not show exception message if it's empty. # Is there a way to preserve the case of the exception class here? --- Zend/zend_default_classes.c | 14 ++++++++++---- Zend/zend_exceptions.c | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Zend/zend_default_classes.c b/Zend/zend_default_classes.c index 0e0fa003b27..95d9e7be8ab 100644 --- a/Zend/zend_default_classes.c +++ b/Zend/zend_default_classes.c @@ -340,9 +340,15 @@ ZEND_METHOD(exception, __toString) zend_call_function(&fci, NULL TSRMLS_CC); - len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s", - Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line), - Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n"); + if (Z_STRLEN_P(message) > 0) { + len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s", + Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line), + Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n"); + } else { + len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s", + Z_OBJCE_P(getThis())->name, Z_STRVAL_P(file), Z_LVAL_P(line), + Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n"); + } /* We store the result in the private property string so we can access * the result in uncaught exception handlers without memleaks. */ @@ -385,7 +391,7 @@ static void zend_register_default_exception(TSRMLS_D) memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); default_exception_handlers.clone_obj = NULL; - zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "none", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_string(default_exception_ptr, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_long(default_exception_ptr, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ptr, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC); diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 0e0fa003b27..95d9e7be8ab 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -340,9 +340,15 @@ ZEND_METHOD(exception, __toString) zend_call_function(&fci, NULL TSRMLS_CC); - len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s", - Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line), - Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n"); + if (Z_STRLEN_P(message) > 0) { + len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s", + Z_OBJCE_P(getThis())->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line), + Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n"); + } else { + len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s", + Z_OBJCE_P(getThis())->name, Z_STRVAL_P(file), Z_LVAL_P(line), + Z_STRLEN_P(trace) ? Z_STRVAL_P(trace) : "#0 {main}\n"); + } /* We store the result in the private property string so we can access * the result in uncaught exception handlers without memleaks. */ @@ -385,7 +391,7 @@ static void zend_register_default_exception(TSRMLS_D) memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); default_exception_handlers.clone_obj = NULL; - zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "none", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_string(default_exception_ptr, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_long(default_exception_ptr, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ptr, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC);