Example #1
0
File: error.c Project: deweerdt/h2o
void
mrb_exc_set(mrb_state *mrb, mrb_value exc)
{
  if (!mrb->gc.out_of_memory && mrb->backtrace.n > 0) {
    mrb_value target_exc = mrb_nil_value();
    int ai;

    ai = mrb_gc_arena_save(mrb);
    if ((mrb->exc && !have_backtrace(mrb, mrb->exc))) {
      target_exc = mrb_obj_value(mrb->exc);
    }
    else if (!mrb_nil_p(exc) && mrb->backtrace.exc) {
      target_exc = mrb_obj_value(mrb->backtrace.exc);
      mrb_gc_protect(mrb, target_exc);
    }
    if (!mrb_nil_p(target_exc)) {
      mrb_value backtrace;
      backtrace = mrb_restore_backtrace(mrb);
      set_backtrace(mrb, target_exc, backtrace);
    }
    mrb_gc_arena_restore(mrb, ai);
  }

  mrb->backtrace.n = 0;
  if (mrb_nil_p(exc)) {
    mrb->exc = 0;
  }
  else {
    if (!mrb_obj_is_kind_of(mrb, exc, mrb->eException_class))
      mrb_raise(mrb, E_TYPE_ERROR, "exception object expected");
    mrb->exc = mrb_obj_ptr(exc);
  }
}
Example #2
0
void oci8_do_raise_init_error(const char *file, int line)
{
    VALUE msg = rb_usascii_str_new_cstr("OCI Library Initialization Error");
    VALUE exc = rb_funcall(eOCIError, oci8_id_new, 2, msg, INT2FIX(-1));

    rb_exc_raise(set_backtrace(exc, file, line));
}
Example #3
0
void oci8_do_raise_by_msgno(ub4 msgno, const char *default_msg, const char *file, int line)
{
    VALUE msg = oci8_get_error_message(msgno, default_msg);
    VALUE exc = rb_funcall(eOCIError, oci8_id_new, 2, msg, INT2FIX(-1));

    rb_exc_raise(set_backtrace(exc, file, line));
}
Example #4
0
void
mrb_exc_set(mrb_state *mrb, mrb_value exc)
{
  if (!mrb->gc.out_of_memory && mrb->backtrace.n > 0) {
    mrb_value target_exc = mrb_nil_value();
    if ((mrb->exc && !have_backtrace(mrb, mrb->exc))) {
      target_exc = mrb_obj_value(mrb->exc);
    }
    else if (!mrb_nil_p(exc) && mrb_obj_ptr(exc) == mrb->backtrace.exc) {
      target_exc = exc;
    }
    if (!mrb_nil_p(target_exc)) {
      mrb_value backtrace;
      backtrace = mrb_restore_backtrace(mrb);
      set_backtrace(mrb, target_exc, backtrace);
    }
  }

  mrb->backtrace.n = 0;
  if (mrb_nil_p(exc)) {
    mrb->exc = 0;
  }
  else {
    mrb->exc = mrb_obj_ptr(exc);
  }
}
Example #5
0
mrb_value
make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr)
{
  mrb_value mesg;
  int n;

  mesg = mrb_nil_value();
  switch (argc) {
    case 0:
    break;
    case 1:
      if (mrb_nil_p(argv[0]))
        break;
      if (isstr) {
        mesg = mrb_check_string_type(mrb, argv[0]);
        if (!mrb_nil_p(mesg)) {
          mesg = mrb_exc_new3(mrb, E_RUNTIME_ERROR, mesg);
          break;
        }
      }
      n = 0;
      goto exception_call;

    case 2:
    case 3:
      n = 1;
exception_call:
      //if (argv[0] == sysstack_error) return argv[0];

      //CONST_ID(mrb, exception, "exception");
      //mesg = mrb_check_funcall(mrb, argv[0], exception, n, argv+1);
      //if (mrb_nil_p(mesg)) {
      //  /* undef */
      //  mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected");
      //}
      if (mrb_respond_to(mrb, argv[0], mrb_intern(mrb, "exception"))) {
        mesg = mrb_funcall_argv(mrb, argv[0], "exception", n, argv+1);
      }
      else {
        /* undef */
        mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected");
      }

      break;
    default:
      mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%d for 0..3)", argc);
      break;
  }
  if (argc > 0) {
    if (!mrb_obj_is_kind_of(mrb, mesg, mrb->eException_class))
      mrb_raise(mrb, E_TYPE_ERROR, "exception object expected");
    if (argc > 2)
        set_backtrace(mrb, mesg, argv[2]);
  }

  return mesg;
}
Example #6
0
void oci8_do_raise_by_msgno(ub4 msgno, const char *default_msg, const char *file, int line)
{
    VALUE msg = oci8_get_error_message(msgno, default_msg);
    VALUE args[2];
    args[0] = msg;
    args[1] = INT2FIX(-1);

    rb_exc_raise(set_backtrace(rb_class_new_instance(2, args, eOCIError), file, line));
}
Example #7
0
static void
errat_setter(VALUE val, ID id, VALUE *var)
{
    VALUE err = get_errinfo();
    if (NIL_P(err)) {
	rb_raise(rb_eArgError, "$! not set");
    }
    set_backtrace(err, val);
}
Example #8
0
File: error.c Project: deweerdt/h2o
static mrb_value
make_exception(mrb_state *mrb, int argc, const mrb_value *argv, mrb_bool isstr)
{
  mrb_value mesg;
  int n;

  mesg = mrb_nil_value();
  switch (argc) {
    case 0:
    break;
    case 1:
      if (mrb_nil_p(argv[0]))
        break;
      if (isstr) {
        mesg = mrb_check_string_type(mrb, argv[0]);
        if (!mrb_nil_p(mesg)) {
          mesg = mrb_exc_new_str(mrb, E_RUNTIME_ERROR, mesg);
          break;
        }
      }
      n = 0;
      goto exception_call;

    case 2:
    case 3:
      n = 1;
exception_call:
      {
        mrb_sym exc = mrb_intern_lit(mrb, "exception");
        if (mrb_respond_to(mrb, argv[0], exc)) {
          mesg = mrb_funcall_argv(mrb, argv[0], exc, n, argv+1);
        }
        else {
          /* undef */
          mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected");
        }
      }

      break;
    default:
      mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%S for 0..3)", mrb_fixnum_value(argc));
      break;
  }
  if (argc > 0) {
    if (!mrb_obj_is_kind_of(mrb, mesg, mrb->eException_class))
      mrb_raise(mrb, mrb->eException_class, "exception object expected");
    if (argc > 2)
      set_backtrace(mrb, mesg, argv[2]);
  }

  return mesg;
}
Example #9
0
void oci8_do_raise_init_error(const char *file, int line)
{
    VALUE msg = rb_usascii_str_new_cstr("OCI Library Initialization Error");
    VALUE exc;
    const char *dll_path = oci8_dll_path();

    if (dll_path != NULL) {
        msg = rb_str_buf_cat_ascii(msg, " - ");
        msg = rb_enc_str_buf_cat(msg, dll_path, strlen(dll_path), rb_filesystem_encoding());
    }
    exc = rb_class_new_instance(1, &msg, eOCIError);
    rb_exc_raise(set_backtrace(exc, file, line));
}
Example #10
0
VALUE
rb_make_exception(int argc, VALUE *argv)
{
    VALUE mesg;
    ID exception;
    int n;

    mesg = Qnil;
    switch (argc) {
      case 0:
	//mesg = Qnil;
	mesg = rb_exc_new2(rb_eRuntimeError, "");
	break;
      case 1:
	if (NIL_P(argv[0])) {
	    break;
	}
	if (TYPE(argv[0]) == T_STRING) {
	    mesg = rb_exc_new3(rb_eRuntimeError, argv[0]);
	    break;
	}
	n = 0;
	goto exception_call;

      case 2:
      case 3:
	n = 1;
      exception_call:
	exception = rb_intern("exception");
	if (!rb_respond_to(argv[0], exception)) {
	    rb_raise(rb_eTypeError, "exception class/object expected");
	}
	mesg = rb_funcall(argv[0], exception, n, argv[1]);
	break;
      default:
	rb_raise(rb_eArgError, "wrong number of arguments");
	break;
    }
    if (argc > 0) {
	if (!rb_obj_is_kind_of(mesg, rb_eException))
	    rb_raise(rb_eTypeError, "exception object expected");
	if (argc > 2)
	    set_backtrace(mesg, argv[2]);
    }

    return mesg;
}
Example #11
0
static VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line)
{
    VALUE exc;
    char errmsg[128];
    sb4 errcode = -1;
    VALUE msg;
    VALUE parse_error_offset = Qnil;
    VALUE sql = Qnil;
    int rv;
    int numarg = 1;

    switch (status) {
    case OCI_ERROR:
        exc = eOCIError;
        msg = get_error_msg(errhp, type, "Error", &errcode);
        numarg = 4;
        break;
    case OCI_SUCCESS_WITH_INFO:
        exc = eOCISuccessWithInfo;
        msg = get_error_msg(errhp, type, "Error", &errcode);
        numarg = 4;
        break;
    case OCI_NO_DATA:
        exc = eOCINoData;
        msg = get_error_msg(errhp, type, "No Data", &errcode);
        numarg = 4;
        break;
    case OCI_INVALID_HANDLE:
        exc = eOCIInvalidHandle;
        msg = rb_usascii_str_new_cstr("Invalid Handle");
        break;
    case OCI_NEED_DATA:
        exc = eOCINeedData;
        msg = rb_usascii_str_new_cstr("Need Data");
        break;
    case OCI_STILL_EXECUTING:
        exc = eOCIStillExecuting;
        msg = rb_usascii_str_new_cstr("Still Executing");
        break;
    case OCI_CONTINUE:
        exc = eOCIContinue;
        msg = rb_usascii_str_new_cstr("Continue");
        break;
    default:
        sprintf(errmsg, "Unknown error (%d)", status);
        exc = eOCIException;
        msg = rb_usascii_str_new_cstr(errmsg);
    }
    if (stmthp != NULL) {
        ub2 offset;
        text *text;
        ub4 size;

        rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &offset, 0, OCI_ATTR_PARSE_ERROR_OFFSET, errhp);
        if (rv == OCI_SUCCESS) {
            parse_error_offset = INT2FIX(offset);
        }
        rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &text, &size, OCI_ATTR_STATEMENT, errhp);
        if (rv == OCI_SUCCESS) {
            sql = rb_external_str_new_with_enc(TO_CHARPTR(text), size, oci8_encoding);
        }
    }
    exc = rb_funcall(exc, oci8_id_new, numarg, msg, INT2FIX(errcode), sql, parse_error_offset);
    return set_backtrace(exc, file, line);
}