Back to index

php5  5.3.10
Defines | Functions | Variables
zend_exceptions.c File Reference
#include "zend.h"
#include "zend_API.h"
#include "zend_builtin_functions.h"
#include "zend_interfaces.h"
#include "zend_exceptions.h"
#include "zend_vm.h"

Go to the source code of this file.

Defines

#define DEFAULT_0_PARAMS
#define TRACE_APPEND_CHR(chr)
#define TRACE_APPEND_STRL(val, vallen)
#define TRACE_APPEND_STR(val)   TRACE_APPEND_STRL(val, sizeof(val)-1)
#define TRACE_APPEND_KEY(key)

Functions

void zend_exception_set_previous (zval *exception, zval *add_previous TSRMLS_DC)
void zend_exception_save (TSRMLS_D)
void zend_exception_restore (TSRMLS_D)
void zend_throw_exception_internal (zval *exception TSRMLS_DC)
ZEND_API void zend_clear_exception (TSRMLS_D)
static zend_object_value zend_default_exception_new_ex (zend_class_entry *class_type, int skip_top_traces TSRMLS_DC)
static zend_object_value zend_default_exception_new (zend_class_entry *class_type TSRMLS_DC)
static zend_object_value zend_error_exception_new (zend_class_entry *class_type TSRMLS_DC)
 ZEND_METHOD (exception, __clone)
 ZEND_METHOD (exception, __construct)
 ZEND_METHOD (error_exception, __construct)
static void _default_exception_get_entry (zval *object, char *name, int name_len, zval *return_value TSRMLS_DC)
 ZEND_METHOD (exception, getFile)
 ZEND_METHOD (exception, getLine)
 ZEND_METHOD (exception, getMessage)
 ZEND_METHOD (exception, getCode)
 ZEND_METHOD (exception, getTrace)
 ZEND_METHOD (error_exception, getSeverity)
static int _build_trace_args (zval **arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
static int _build_trace_string (zval **frame TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
 ZEND_METHOD (exception, getTraceAsString)
 ZEND_METHOD (exception, getPrevious)
int zend_spprintf (char **message, int max_len, char *format,...)
 ZEND_METHOD (exception, __toString)
void zend_register_default_exception (TSRMLS_D)
ZEND_API zend_class_entry * zend_exception_get_default (TSRMLS_D)
ZEND_API zend_class_entry * zend_get_error_exception (TSRMLS_D)
ZEND_API zval * zend_throw_exception (zend_class_entry *exception_ce, char *message, long code TSRMLS_DC)
ZEND_API zval * zend_throw_exception_ex (zend_class_entry *exception_ce, long code TSRMLS_DC, char *format,...)
ZEND_API zval * zend_throw_error_exception (zend_class_entry *exception_ce, char *message, long code, int severity TSRMLS_DC)
static void zend_error_va (int type, const char *file, uint lineno, const char *format,...)
ZEND_API void zend_exception_error (zval *exception, int severity TSRMLS_DC)
ZEND_API void zend_throw_exception_object (zval *exception TSRMLS_DC)

Variables

zend_class_entry * default_exception_ce
zend_class_entry * error_exception_ce
static zend_object_handlers default_exception_handlers
ZEND_API void(* zend_throw_exception_hook )(zval *ex TSRMLS_DC)
static const zend_function_entry default_exception_functions []
static const zend_function_entry error_exception_functions []

Define Documentation

Value:
if (zend_parse_parameters_none() == FAILURE) { \
              return; \
       }

Definition at line 247 of file zend_exceptions.c.

#define TRACE_APPEND_CHR (   chr)
Value:
*str = (char*)erealloc(*str, *len + 1 + 1);                          \
       (*str)[(*len)++] = chr

Definition at line 325 of file zend_exceptions.c.

#define TRACE_APPEND_KEY (   key)
Value:
if (zend_hash_find(ht, key, sizeof(key), (void**)&tmp) == SUCCESS) { \
           TRACE_APPEND_STRL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));           \
       }

Definition at line 340 of file zend_exceptions.c.

#define TRACE_APPEND_STR (   val)    TRACE_APPEND_STRL(val, sizeof(val)-1)

Definition at line 337 of file zend_exceptions.c.

#define TRACE_APPEND_STRL (   val,
  vallen 
)
Value:
{                                                                    \
              int l = vallen;                                                  \
              *str = (char*)erealloc(*str, *len + l + 1);                      \
              memcpy((*str) + *len, val, l);                                   \
              *len += l;                                                       \
       }

Definition at line 329 of file zend_exceptions.c.


Function Documentation

static int _build_trace_args ( zval **arg  TSRMLS_DC,
int  num_args,
va_list  args,
zend_hash_key hash_key 
) [static]

Definition at line 347 of file zend_exceptions.c.

{
       char **str;
       int *len;

       str = va_arg(args, char**);
       len = va_arg(args, int*);

       /* the trivial way would be to do:
        * conver_to_string_ex(arg);
        * append it and kill the now tmp arg.
        * but that could cause some E_NOTICE and also damn long lines.
        */

       switch (Z_TYPE_PP(arg)) {
              case IS_NULL:
                     TRACE_APPEND_STR("NULL, ");
                     break;
              case IS_STRING: {
                     int l_added;
                     TRACE_APPEND_CHR('\'');
                     if (Z_STRLEN_PP(arg) > 15) {
                            TRACE_APPEND_STRL(Z_STRVAL_PP(arg), 15);
                            TRACE_APPEND_STR("...', ");
                            l_added = 15 + 6 + 1; /* +1 because of while (--l_added) */
                     } else {
                            l_added = Z_STRLEN_PP(arg);
                            TRACE_APPEND_STRL(Z_STRVAL_PP(arg), l_added);
                            TRACE_APPEND_STR("', ");
                            l_added += 3 + 1;
                     }
                     while (--l_added) {
                            if ((*str)[*len - l_added] < 32) {
                                   (*str)[*len - l_added] = '?';
                            }
                     }
                     break;
              }
              case IS_BOOL:
                     if (Z_LVAL_PP(arg)) {
                            TRACE_APPEND_STR("true, ");
                     } else {
                            TRACE_APPEND_STR("false, ");
                     }
                     break;
              case IS_RESOURCE:
                     TRACE_APPEND_STR("Resource id #");
                     /* break; */
              case IS_LONG: {
                     long lval = Z_LVAL_PP(arg);
                     char s_tmp[MAX_LENGTH_OF_LONG + 1];
                     int l_tmp = zend_sprintf(s_tmp, "%ld", lval);  /* SAFE */
                     TRACE_APPEND_STRL(s_tmp, l_tmp);
                     TRACE_APPEND_STR(", ");
                     break;
              }
              case IS_DOUBLE: {
                     double dval = Z_DVAL_PP(arg);
                     char *s_tmp;
                     int l_tmp;

                     s_tmp = emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1);
                     l_tmp = zend_sprintf(s_tmp, "%.*G", (int) EG(precision), dval);  /* SAFE */
                     TRACE_APPEND_STRL(s_tmp, l_tmp);
                     /* %G already handles removing trailing zeros from the fractional part, yay */
                     efree(s_tmp);
                     TRACE_APPEND_STR(", ");
                     break;
              }
              case IS_ARRAY:
                     TRACE_APPEND_STR("Array, ");
                     break;
              case IS_OBJECT: {
                     char *class_name;
                     zend_uint class_name_len;
                     int dup;

                     TRACE_APPEND_STR("Object(");

                     dup = zend_get_object_classname(*arg, &class_name, &class_name_len TSRMLS_CC);

                     TRACE_APPEND_STRL(class_name, class_name_len);
                     if(!dup) {
                            efree(class_name);
                     }

                     TRACE_APPEND_STR("), ");
                     break;
              }
              default:
                     break;
       }
       return ZEND_HASH_APPLY_KEEP;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int _build_trace_string ( zval **frame  TSRMLS_DC,
int  num_args,
va_list  args,
zend_hash_key hash_key 
) [static]

Definition at line 443 of file zend_exceptions.c.

{
       char *s_tmp, **str;
       int *len, *num;
       long line;
       HashTable *ht = Z_ARRVAL_PP(frame);
       zval **file, **tmp;

       str = va_arg(args, char**);
       len = va_arg(args, int*);
       num = va_arg(args, int*);

       s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1);
       sprintf(s_tmp, "#%d ", (*num)++);
       TRACE_APPEND_STRL(s_tmp, strlen(s_tmp));
       efree(s_tmp);
       if (zend_hash_find(ht, "file", sizeof("file"), (void**)&file) == SUCCESS) {
              if (zend_hash_find(ht, "line", sizeof("line"), (void**)&tmp) == SUCCESS) {
                     line = Z_LVAL_PP(tmp);
              } else {
                     line = 0;
              }
              s_tmp = emalloc(Z_STRLEN_PP(file) + MAX_LENGTH_OF_LONG + 4 + 1);
              sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_PP(file), line);
              TRACE_APPEND_STRL(s_tmp, strlen(s_tmp));
              efree(s_tmp);
       } else {
              TRACE_APPEND_STR("[internal function]: ");
       }
       TRACE_APPEND_KEY("class");
       TRACE_APPEND_KEY("type");
       TRACE_APPEND_KEY("function");
       TRACE_APPEND_CHR('(');
       if (zend_hash_find(ht, "args", sizeof("args"), (void**)&tmp) == SUCCESS) {
              int last_len = *len;
              zend_hash_apply_with_arguments(Z_ARRVAL_PP(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 2, str, len);
              if (last_len != *len) {
                     *len -= 2; /* remove last ', ' */
              }
       }
       TRACE_APPEND_STR(")\n");
       return ZEND_HASH_APPLY_KEEP;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _default_exception_get_entry ( zval *  object,
char *  name,
int  name_len,
zval *return_value  TSRMLS_DC 
) [static]

Definition at line 252 of file zend_exceptions.c.

{
       zval *value;

       value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC);

       *return_value = *value;
       zval_copy_ctor(return_value);
       INIT_PZVAL(return_value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 114 of file zend_exceptions.c.

{
       if (EG(prev_exception)) {
              zval_ptr_dtor(&EG(prev_exception));
              EG(prev_exception) = NULL;
       }
       if (!EG(exception)) {
              return;
       }
       zval_ptr_dtor(&EG(exception));
       EG(exception) = NULL;
       EG(current_execute_data)->opline = EG(opline_before_exception);
#if ZEND_DEBUG
       EG(opline_before_exception) = NULL;
#endif
}

Here is the caller graph for this function:

static zend_object_value zend_default_exception_new ( zend_class_entry *class_type  TSRMLS_DC) [static]

Definition at line 158 of file zend_exceptions.c.

{
       return zend_default_exception_new_ex(class_type, 0 TSRMLS_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static zend_object_value zend_default_exception_new_ex ( zend_class_entry *  class_type,
int skip_top_traces  TSRMLS_DC 
) [static]

Definition at line 132 of file zend_exceptions.c.

{
       zval tmp, obj;
       zend_object *object;
       zval *trace;

       Z_OBJVAL(obj) = zend_objects_new(&object, class_type TSRMLS_CC);
       Z_OBJ_HT(obj) = &default_exception_handlers;

       ALLOC_HASHTABLE(object->properties);
       zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
       zend_hash_copy(object->properties, &class_type->default_properties, zval_copy_property_ctor(class_type), (void *) &tmp, sizeof(zval *));

       ALLOC_ZVAL(trace);
       Z_UNSET_ISREF_P(trace);
       Z_SET_REFCOUNT_P(trace, 0);
       zend_fetch_debug_backtrace(trace, skip_top_traces, 0 TSRMLS_CC);

       zend_update_property_string(default_exception_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC);
       zend_update_property_long(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
       zend_update_property(default_exception_ce, &obj, "trace", sizeof("trace")-1, trace TSRMLS_CC);

       return Z_OBJVAL(obj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static zend_object_value zend_error_exception_new ( zend_class_entry *class_type  TSRMLS_DC) [static]

Definition at line 164 of file zend_exceptions.c.

{
       return zend_default_exception_new_ex(class_type, 2 TSRMLS_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void zend_error_va ( int  type,
const char *  file,
uint  lineno,
const char *  format,
  ... 
) [static]

Definition at line 748 of file zend_exceptions.c.

{
       va_list args;

       va_start(args, format);
       zend_error_cb(type, file, lineno, format, args);
       va_end(args);
}

Here is the caller graph for this function:

ZEND_API void zend_exception_error ( zval *  exception,
int severity  TSRMLS_DC 
)

Definition at line 759 of file zend_exceptions.c.

{
       zend_class_entry *ce_exception = Z_OBJCE_P(exception);
       if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
              zval *str, *file, *line;

              EG(exception) = NULL;

              zend_call_method_with_0_params(&exception, ce_exception, NULL, "__tostring", &str);
              if (!EG(exception)) {
                     if (Z_TYPE_P(str) != IS_STRING) {
                            zend_error(E_WARNING, "%s::__toString() must return a string", ce_exception->name);
                     } else {
                            zend_update_property_string(default_exception_ce, exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC);
                     }
              }
              zval_ptr_dtor(&str);

              if (EG(exception)) {
                     /* do the best we can to inform about the inner exception */
                     if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
                            file = zend_read_property(default_exception_ce, EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC);
                            line = zend_read_property(default_exception_ce, EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC);
                     } else {
                            file = NULL;
                            line = NULL;
                     }
                     zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE_P(EG(exception))->name, ce_exception->name);
              }

              str = zend_read_property(default_exception_ce, exception, "string", sizeof("string")-1, 1 TSRMLS_CC);
              file = zend_read_property(default_exception_ce, exception, "file", sizeof("file")-1, 1 TSRMLS_CC);
              line = zend_read_property(default_exception_ce, exception, "line", sizeof("line")-1, 1 TSRMLS_CC);

              zend_error_va(severity, Z_STRVAL_P(file), Z_LVAL_P(line), "Uncaught %s\n  thrown", Z_STRVAL_P(str));
       } else {
              zend_error(severity, "Uncaught exception '%s'", ce_exception->name);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API zend_class_entry* zend_exception_get_default ( TSRMLS_D  )

Definition at line 685 of file zend_exceptions.c.

Here is the caller graph for this function:

Definition at line 70 of file zend_exceptions.c.

{
       if (EG(prev_exception)) {
              if (EG(exception)) {
                     zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC);
              } else {
                     EG(exception) = EG(prev_exception);
              }
              EG(prev_exception) = NULL;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 58 of file zend_exceptions.c.

{
       if (EG(prev_exception)) {
              zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC);
       }
       if (EG(exception)) {
              EG(prev_exception) = EG(exception);
       }
       EG(exception) = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void zend_exception_set_previous ( zval *  exception,
zval *add_previous  TSRMLS_DC 
)

Definition at line 36 of file zend_exceptions.c.

{
       zval *previous;

       if (exception == add_previous || !add_previous || !exception) {
              return;
       }
       if (Z_TYPE_P(add_previous) != IS_OBJECT && !instanceof_function(Z_OBJCE_P(add_previous), default_exception_ce TSRMLS_CC)) {
              zend_error(E_ERROR, "Cannot set non exception as previous exception");
              return;
       }
       while (exception && exception != add_previous && Z_OBJ_HANDLE_P(exception) != Z_OBJ_HANDLE_P(add_previous)) {
              previous = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC);
              if (Z_TYPE_P(previous) == IS_NULL) {
                     zend_update_property(default_exception_ce, exception, "previous", sizeof("previous")-1, add_previous TSRMLS_CC);
                     Z_DELREF_P(add_previous);
                     return;
              }
              exception = previous;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API zend_class_entry* zend_get_error_exception ( TSRMLS_D  )

Definition at line 691 of file zend_exceptions.c.

{
       return error_exception_ce;
}
ZEND_METHOD ( exception  ,
__clone   
)

Definition at line 172 of file zend_exceptions.c.

{
       /* Should never be executable */
       zend_throw_exception(NULL, "Cannot clone object using __clone()", 0 TSRMLS_CC);
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
__construct   
)

Definition at line 181 of file zend_exceptions.c.

{
       char  *message = NULL;
       long   code = 0;
       zval  *object, *previous = NULL;
       int    argc = ZEND_NUM_ARGS(), message_len;

       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|slO!", &message, &message_len, &code, &previous, default_exception_ce) == FAILURE) {
              zend_error(E_ERROR, "Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]])");
       }

       object = getThis();

       if (message) {
              zend_update_property_string(default_exception_ce, object, "message", sizeof("message")-1, message TSRMLS_CC);
       }

       if (code) {
              zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC);
       }

       if (previous) {
              zend_update_property(default_exception_ce, object, "previous", sizeof("previous")-1, previous TSRMLS_CC);
       }
}

Here is the call graph for this function:

ZEND_METHOD ( error_exception  ,
__construct   
)

Definition at line 210 of file zend_exceptions.c.

{
       char  *message = NULL, *filename = NULL;
       long   code = 0, severity = E_ERROR, lineno;
       zval  *object, *previous = NULL;
       int    argc = ZEND_NUM_ARGS(), message_len, filename_len;

       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, default_exception_ce) == FAILURE) {
              zend_error(E_ERROR, "Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno  [, Exception $previous = NULL]]]]]])");
       }

       object = getThis();

       if (message) {
              zend_update_property_string(default_exception_ce, object, "message", sizeof("message")-1, message TSRMLS_CC);
       }

       if (code) {
              zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC);
       }

       if (previous) {
              zend_update_property(default_exception_ce, object, "previous", sizeof("previous")-1, previous TSRMLS_CC);
       }

       zend_update_property_long(default_exception_ce, object, "severity", sizeof("severity")-1, severity TSRMLS_CC);

       if (argc >= 4) {
           zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, filename TSRMLS_CC);
       if (argc < 5) {
           lineno = 0; /* invalidate lineno */
       }
       zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC);
       }
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
getFile   
)

Definition at line 266 of file zend_exceptions.c.

{
       DEFAULT_0_PARAMS;

       _default_exception_get_entry(getThis(), "file", sizeof("file")-1, return_value TSRMLS_CC);
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
getLine   
)

Definition at line 276 of file zend_exceptions.c.

{
       DEFAULT_0_PARAMS;

       _default_exception_get_entry(getThis(), "line", sizeof("line")-1, return_value TSRMLS_CC);
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
getMessage   
)

Definition at line 286 of file zend_exceptions.c.

{
       DEFAULT_0_PARAMS;

       _default_exception_get_entry(getThis(), "message", sizeof("message")-1, return_value TSRMLS_CC);
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
getCode   
)

Definition at line 296 of file zend_exceptions.c.

{
       DEFAULT_0_PARAMS;

       _default_exception_get_entry(getThis(), "code", sizeof("code")-1, return_value TSRMLS_CC);
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
getTrace   
)

Definition at line 306 of file zend_exceptions.c.

{
       DEFAULT_0_PARAMS;

       _default_exception_get_entry(getThis(), "trace", sizeof("trace")-1, return_value TSRMLS_CC);
}

Here is the call graph for this function:

ZEND_METHOD ( error_exception  ,
getSeverity   
)

Definition at line 316 of file zend_exceptions.c.

{
       DEFAULT_0_PARAMS;

       _default_exception_get_entry(getThis(), "severity", sizeof("severity")-1, return_value TSRMLS_CC);
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
getTraceAsString   
)

Definition at line 490 of file zend_exceptions.c.

{
       zval *trace;
       char *res, **str, *s_tmp;
       int res_len = 0, *len = &res_len, num = 0;

       DEFAULT_0_PARAMS;
       
       res = estrdup("");
       str = &res;

       trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC);
       zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 3, str, len, &num);

       s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 7 + 1);
       sprintf(s_tmp, "#%d {main}", num);
       TRACE_APPEND_STRL(s_tmp, strlen(s_tmp));
       efree(s_tmp);

       res[res_len] = '\0'; 
       RETURN_STRINGL(res, res_len, 0); 
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
getPrevious   
)

Definition at line 516 of file zend_exceptions.c.

{
       zval *previous;

       DEFAULT_0_PARAMS;

       previous = zend_read_property(default_exception_ce, getThis(), "previous", sizeof("previous")-1, 1 TSRMLS_CC);
       RETURN_ZVAL(previous, 1, 0);
}

Here is the call graph for this function:

ZEND_METHOD ( exception  ,
__toString   
)

Definition at line 540 of file zend_exceptions.c.

{
       zval message, file, line, *trace, *exception;
       char *str, *prev_str;
       int len = 0;
       zend_fcall_info fci;
       zval fname;
       
       DEFAULT_0_PARAMS;
       
       str = estrndup("", 0);

       exception = getThis();
       ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1, 1);

       while (exception && Z_TYPE_P(exception) == IS_OBJECT) {
              prev_str = str;
              _default_exception_get_entry(exception, "message", sizeof("message")-1, &message TSRMLS_CC);
              _default_exception_get_entry(exception, "file", sizeof("file")-1, &file TSRMLS_CC);
              _default_exception_get_entry(exception, "line", sizeof("line")-1, &line TSRMLS_CC);

              convert_to_string(&message);
              convert_to_string(&file);
              convert_to_long(&line);

              fci.size = sizeof(fci);
              fci.function_table = &Z_OBJCE_P(exception)->function_table;
              fci.function_name = &fname;
              fci.symbol_table = NULL;
              fci.object_ptr = exception;
              fci.retval_ptr_ptr = &trace;
              fci.param_count = 0;
              fci.params = NULL;
              fci.no_separation = 1;

              zend_call_function(&fci, NULL TSRMLS_CC);

              if (Z_TYPE_P(trace) != IS_STRING) {
                     zval_ptr_dtor(&trace);
                     trace = NULL;
              }

              if (Z_STRLEN(message) > 0) {
                     len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s",
                                                        Z_OBJCE_P(exception)->name, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line),
                                                        (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n",
                                                        len ? "\n\nNext " : "", prev_str);
              } else {
                     len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s",
                                                        Z_OBJCE_P(exception)->name, Z_STRVAL(file), Z_LVAL(line),
                                                        (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n",
                                                        len ? "\n\nNext " : "", prev_str);
              }
              efree(prev_str);
              zval_dtor(&message);
              zval_dtor(&file);
              zval_dtor(&line);

              exception = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 0 TSRMLS_CC);

              if (trace) {
                     zval_ptr_dtor(&trace);
              }
       }
       zval_dtor(&fname);

       /* We store the result in the private property string so we can access
        * the result in uncaught exception handlers without memleaks. */
       zend_update_property_string(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC);

       RETURN_STRINGL(str, len, 0);
}

Here is the call graph for this function:

Definition at line 660 of file zend_exceptions.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int zend_spprintf ( char **  message,
int  max_len,
char *  format,
  ... 
)

Definition at line 526 of file zend_exceptions.c.

{
       va_list arg;
       int len;

       va_start(arg, format);
       len = zend_vspprintf(message, max_len, format, arg);
       va_end(arg);
       return len;
}

Here is the caller graph for this function:

ZEND_API zval* zend_throw_error_exception ( zend_class_entry *  exception_ce,
char *  message,
long  code,
int severity  TSRMLS_DC 
)

Definition at line 740 of file zend_exceptions.c.

{
       zval *ex = zend_throw_exception(exception_ce, message, code TSRMLS_CC);
       zend_update_property_long(default_exception_ce, ex, "severity", sizeof("severity")-1, severity TSRMLS_CC);
       return ex;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API zval* zend_throw_exception ( zend_class_entry *  exception_ce,
char *  message,
long code  TSRMLS_DC 
)

Definition at line 697 of file zend_exceptions.c.

{
       zval *ex;

       MAKE_STD_ZVAL(ex);
       if (exception_ce) {
              if (!instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) {
                     zend_error(E_NOTICE, "Exceptions must be derived from the Exception base class");
                     exception_ce = default_exception_ce;
              }
       } else {
              exception_ce = default_exception_ce;
       }
       object_init_ex(ex, exception_ce);


       if (message) {
              zend_update_property_string(default_exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC);
       }
       if (code) {
              zend_update_property_long(default_exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC);
       }

       zend_throw_exception_internal(ex TSRMLS_CC);
       return ex;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API zval* zend_throw_exception_ex ( zend_class_entry *  exception_ce,
long code  TSRMLS_DC,
char *  format,
  ... 
)

Definition at line 725 of file zend_exceptions.c.

{
       va_list arg;
       char *message;
       zval *zexception;

       va_start(arg, format);
       zend_vspprintf(&message, 0, format, arg);
       va_end(arg);
       zexception = zend_throw_exception(exception_ce, message, code TSRMLS_CC);
       efree(message);
       return zexception;
}

Here is the call graph for this function:

void zend_throw_exception_internal ( zval *exception  TSRMLS_DC)

Definition at line 83 of file zend_exceptions.c.

{
       if (exception != NULL) {
              zval *previous = EG(exception);
              zend_exception_set_previous(exception, EG(exception) TSRMLS_CC);
              EG(exception) = exception;
              if (previous) {
                     return;
              }
       }
       if (!EG(current_execute_data)) {
              if(EG(exception)) {
                     zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
              }
              zend_error(E_ERROR, "Exception thrown without a stack frame");
       }

       if (zend_throw_exception_hook) {
              zend_throw_exception_hook(exception TSRMLS_CC);
       }

       if (EG(current_execute_data)->opline == NULL ||
           (EG(current_execute_data)->opline+1)->opcode == ZEND_HANDLE_EXCEPTION) {
              /* no need to rethrow the exception */
              return;
       }
       EG(opline_before_exception) = EG(current_execute_data)->opline;
       EG(current_execute_data)->opline = EG(exception_op);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API void zend_throw_exception_object ( zval *exception  TSRMLS_DC)

Definition at line 800 of file zend_exceptions.c.

{
       zend_class_entry *exception_ce;

       if (exception == NULL || Z_TYPE_P(exception) != IS_OBJECT) {
              zend_error(E_ERROR, "Need to supply an object when throwing an exception");
       }

       exception_ce = Z_OBJCE_P(exception);

       if (!exception_ce || !instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) {
              zend_error(E_ERROR, "Exceptions must be valid objects derived from the Exception base class");
       }
       zend_throw_exception_internal(exception TSRMLS_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

zend_class_entry* default_exception_ce

Definition at line 31 of file zend_exceptions.c.

Initial value:
 {









       ZEND_ME(exception, __toString, NULL, 0)
       {NULL, NULL, NULL}
}

Definition at line 630 of file zend_exceptions.c.

zend_object_handlers default_exception_handlers [static]

Definition at line 33 of file zend_exceptions.c.

zend_class_entry* error_exception_ce

Definition at line 32 of file zend_exceptions.c.

Initial value:
 {

       ZEND_ME(error_exception, getSeverity, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
       {NULL, NULL, NULL}
}

Definition at line 653 of file zend_exceptions.c.

Definition at line 34 of file zend_exceptions.c.