예제 #1
0
파일: objspace.py 프로젝트: fniephaus/topaz
 def error(self, w_type, msg="", optargs=None):
     if not optargs:
         optargs = []
     args_w = [self.newstr_fromstr(msg)] + optargs
     w_exc = self.send(w_type, "new", args_w)
     assert isinstance(w_exc, W_ExceptionObject)
     return RubyError(w_exc)
예제 #2
0
    def method_raise(self,
                     space,
                     w_str_or_exception=None,
                     w_string=None,
                     w_array=None):
        w_exception = None
        if w_str_or_exception is None:
            w_exception = space.globals.get(space, "$!") or space.w_nil
            if w_exception is space.w_nil:
                w_exception = space.w_RuntimeError
        elif isinstance(w_str_or_exception, W_StringObject):
            w_exception = space.w_RuntimeError
            w_string = w_str_or_exception
        else:
            w_exception = w_str_or_exception

        if not space.respond_to(w_exception, "exception"):
            raise space.error(space.w_TypeError,
                              "exception class/object expected")

        if w_string is not None:
            w_exc = space.send(w_exception, "exception", [w_string])
        else:
            w_exc = space.send(w_exception, "exception")

        if w_array is not None:
            raise space.error(space.w_NotImplementedError,
                              "custom backtrace for Kernel#raise")

        if not isinstance(w_exc, W_ExceptionObject):
            raise space.error(space.w_TypeError, "exception object expected")

        raise RubyError(w_exc)