summaryrefslogtreecommitdiff
path: root/Zend/zend.c
diff options
context:
space:
mode:
authorAaron Piotrowski <aaron@trowski.com>2015-07-03 13:41:17 -0500
committerAaron Piotrowski <aaron@trowski.com>2015-07-03 17:53:40 -0500
commit5a99c07eccb09c3c8b9f6fe4b83020163aad6498 (patch)
tree2405c51d16e14ca24fed2811148220388798b222 /Zend/zend.c
parent866bd89b1d909795bd5ae72121089aef5e0fb204 (diff)
downloadphp-git-5a99c07eccb09c3c8b9f6fe4b83020163aad6498.tar.gz
Enable throwing custom exceptions from errors
Diffstat (limited to 'Zend/zend.c')
-rw-r--r--Zend/zend.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/Zend/zend.c b/Zend/zend.c
index e824b75c8d..b60a60413e 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -1049,25 +1049,6 @@ static void zend_error_va_list(int type, const char *format, va_list args)
zend_stack delayed_oplines_stack;
zend_array *symbol_table;
- if (type & E_EXCEPTION) {
- type &= ~E_EXCEPTION;
- //TODO: we can't convert compile-time errors to exceptions yet???
- if (EG(current_execute_data) && !CG(in_compilation)) {
- char *message = NULL;
-
-#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
- va_start(args, format);
-#endif
- zend_vspprintf(&message, 0, format, args);
- zend_throw_exception(zend_ce_error, message, type);
- efree(message);
-#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
- va_end(args);
-#endif
- return;
- }
- }
-
/* Report about uncaught exception in case of fatal errors */
if (EG(exception)) {
zend_execute_data *ex;
@@ -1311,6 +1292,31 @@ ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ..
# endif
#endif
+ZEND_API void zend_throw_error(zend_class_entry *exception_ce, int type, const char *format, ...) /* {{{ */
+{
+ va_list va;
+ char *message = NULL;
+
+ va_start(va, format);
+ zend_vspprintf(&message, 0, format, va);
+
+ if (type & E_EXCEPTION) {
+ type = E_ERROR; // Convert to E_ERROR if unable to throw.
+ //TODO: we can't convert compile-time errors to exceptions yet???
+ if (EG(current_execute_data) && !CG(in_compilation)) {
+ zend_throw_exception(exception_ce, message, type);
+ efree(message);
+ va_end(va);
+ return;
+ }
+ }
+
+ zend_error(type, message);
+ efree(message);
+ va_end(va);
+}
+/* }}} */
+
ZEND_API void zend_type_error(const char *format, ...) /* {{{ */
{
va_list va;