pike.git / src / error.c

version» Context lines:

pike.git/src/error.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: error.c,v 1.147 2006/08/21 18:29:09 grubba Exp $ + || $Id: error.c,v 1.148 2006/09/20 16:15:55 mast Exp $   */      #define NO_PIKE_SHORTHAND   #include "global.h"   #include "svalue.h"   #include "pike_macros.h"   #include "pike_error.h"   #include "interpret.h"   #include "stralloc.h"   #include "builtin_functions.h"
pike.git/src/error.c:621: Inside #if 1
  /*! @endclass    */      /*! @module Error    */      /*! @class Generic    *! Class for exception objects for errors of unspecified type.    */    + /*! @decl string error_message +  *! +  *! The error message. It always ends with a newline (@expr{'\n'@}) +  *! character and it might be more than one line. +  *! +  *! Code that catches and rethrows errors may extend this with more +  *! error information. +  */ +  + /*! @decl array(backtrace_frame|array(mixed)) error_backtrace +  *! +  *! The backtrace as returned by @[backtrace] where the error +  *! occurred. +  *! +  *! Code that catches and rethrows errors should ensure that this +  *! remains the same in the rethrown error. +  */ +    #define ERR_DECLARE   #include "errors.h"      /*! @decl array cast(string type)    *!    *! Cast operator.    *!    *! @note    *! The only supported type to cast to is @expr{"array"@}, which -  *! generates and old-style error. +  *! generates an old-style error @expr{({@[message](), +  *! @[backtrace]()})@}.    */   static void f_error_cast(INT32 args)   {    char *s;    get_all_args("error->cast",args,"%s",&s);    if(!strncmp(s,"array",5))    {    pop_n_elems(args); -  if(GENERIC_ERROR_THIS->error_message) -  ref_push_string(GENERIC_ERROR_THIS->error_message); -  else -  push_int(0); -  if(GENERIC_ERROR_THIS->error_backtrace) -  ref_push_array(GENERIC_ERROR_THIS->error_backtrace); -  else -  push_int(0); +  apply_current (generic_err_message_fun, 0); +  apply_current (generic_err_backtrace_fun, 0);    f_aggregate(2);    }else{    SIMPLE_BAD_ARG_ERROR("error->cast", 1, "the value \"array\"");    }   }      /*! @decl array|string `[](int(0..1) index)    *!    *! Index operator.    *!    *! Simulates an array    *! @array    *! @elem string msg -  *! Error message. +  *! Error message as returned by @[message].    *! @elem array backtrace -  *! Backtrace as returned by @[backtrace()] from where -  *! the error occurred. +  *! Backtrace as returned by @[backtrace].    *! @endarray    *!    *! @note    *! The error message is always terminated with a newline.    *!    *! @seealso    *! @[backtrace()]    */   static void f_error_index(INT32 args)   {    INT_TYPE ind;    get_all_args("error->`[]",args,"%i",&ind);       switch(ind)    {    case 0:    pop_n_elems(args); -  if(GENERIC_ERROR_THIS->error_message) -  ref_push_string(GENERIC_ERROR_THIS->error_message); -  else -  push_int(0); +  apply_current (generic_err_message_fun, 0);    break;    case 1:    pop_n_elems(args); -  if(GENERIC_ERROR_THIS->error_backtrace) -  ref_push_array(GENERIC_ERROR_THIS->error_backtrace); -  else -  push_int(0); +  apply_current (generic_err_backtrace_fun, 0);    break;    default:    index_error("error->`[]", Pike_sp-args, args, NULL, Pike_sp-args,    "Index %"PRINTPIKEINT"d is out of range 0..1.\n", ind);    break;    }   }      /*! @decl string describe()    *!
pike.git/src/error.c:713:    */   static void f_error_describe(INT32 args)   {    pop_n_elems(args);    ref_push_object(Pike_fp->current_object);    APPLY_MASTER("describe_backtrace",1);   }      /*! @decl string message()    *! -  *! Return a readable message describing the error. +  *! Return a readable message describing the error. Normally simply +  *! returns @[error_message]. +  *! +  *! If you override this function then you should ensure that +  *! @[error_message] is included in the returned message, since there +  *! might be code that catches your error objects, extends +  *! @[error_message] with more info, and rethrows the error.    */   static void f_error_message(INT32 args)   {    pop_n_elems(args);    if (GENERIC_ERROR_THIS->error_message)    ref_push_string (GENERIC_ERROR_THIS->error_message);    else    push_int (0);   }      /*! @decl array backtrace()    *! -  *! Return the backtrace where the error occurred. +  *! Return the backtrace where the error occurred. Normally simply +  *! returns @[error_backtrace].    *!    *! @seealso    *! @[predef::backtrace()]    */   static void f_error_backtrace(INT32 args)   {    pop_n_elems(args);    if(GENERIC_ERROR_THIS->error_backtrace)    ref_push_array(GENERIC_ERROR_THIS->error_backtrace);    else
pike.git/src/error.c:769:    if(GENERIC_ERROR_THIS->error_message)    ref_push_string(GENERIC_ERROR_THIS->error_message);    else    push_int(0);    f_sprintf(2);    f_add(3);   }      /*! @decl int(0..1) _is_type(string t)    *! -  *! Claims that the error object is an array. +  *! Claims that the error object is an array, for compatibility with +  *! old style error handling code.    */   static void f_error__is_type(INT32 args)   {    struct pike_string *array_string;    int ret;    MAKE_CONST_STRING(array_string, "array");    if (args < 0) SIMPLE_TOO_FEW_ARGS_ERROR("_is_type", 1);    if (args > 1) SIMPLE_WRONG_NUM_ARGS_ERROR("_is_type", 1);    if (Pike_sp[-args].type != PIKE_T_STRING)    SIMPLE_ARG_TYPE_ERROR("_is_type", 1, "string");    ret = Pike_sp[-args].u.string == array_string;    pop_n_elems(args);    push_int(ret);   }    - /*! @decl void create(string message) + /*! @decl void create(string message, @ +  *! void|array(backtrace_frame|array(mixed)) backtrace)    */   static void f_error_create(INT32 args)   {    struct pike_string *msg;    struct array *bt = NULL;       get_all_args("create", args, "%W.%A", &msg, &bt);       do_free_string(GENERIC_ERROR_THIS->error_message);    copy_shared_string(GENERIC_ERROR_THIS->error_message, msg);