src/exception.cpp in rucy-0.1.6 vs src/exception.cpp in rucy-0.1.7

- old
+ new

@@ -1,15 +1,16 @@ // -*- c++ -*- #include "rucy/exception.h" -#include <ruby.h> -#include <rucy/rucy.h> - +#include <typeinfo> #ifdef WIN32 #include <windows.h> #endif +#include <xot/exception.h> +#include "rucy/ruby.h" +#include "rucy/rucy.h" namespace Rucy { @@ -17,133 +18,147 @@ RubyException::RubyException (Value exception) : Super(""), val(exception) { } - RubyException::RubyException (Value type, const char* format, ...) - : Super(""), val(Qnil) + RubyException::RubyException (Value exception, const char* format, ...) + : Super(""), val(nil()) { XOT_STRINGF(format, s); - val = rb_exc_new2(type, s.c_str()); + val = rb_exc_new2(exception, s.c_str()); } const char* RubyException::what () const throw() { - SYM(message); + RUCY_SYM(message); return value().call(message).c_str(); } Value RubyException::value () const { return val; } - RubyJumptag::RubyJumptag (int tag) + RubyJumpTag::RubyJumpTag (int tag) : tag(tag) { } void raise (const char* format, ...) { if (!format) throw; - XOT_STRINGF(format, message); - throw message; + XOT_STRINGF(format, s); + throw s.c_str(); } void - raise (VALUE exception, const char* format, ...) + raise (RubyValue exception, const char* format, ...) { - XOT_STRINGF(format, message); - throw RubyException(exception, message.c_str()); + XOT_STRINGF(format, s); + throw RubyException(exception, s.c_str()); } void - type_error (const char* format, ...) + rucy_error (const char* file, int line, const char* format, ...) { - XOT_STRINGF(format, message); - raise(rb_eTypeError, message.c_str()); + XOT_STRINGF(format, s); + raise(Xot::error_text(file, line, s)); } void - argument_error (const char* format, ...) + type_error (const char* file, int line, const char* format, ...) { - XOT_STRINGF(format, message); - raise(rb_eArgError, message.c_str()); + XOT_STRINGF(format, s); + raise(rb_eTypeError, Xot::error_text(file, line, s)); } void + argument_error (const char* file, int line, const char* format, ...) + { + XOT_STRINGF(format, s); + raise(rb_eArgError, Xot::error_text(file, line, s)); + } + + void arg_count_error ( + const char* file, int line, const char* method, int nargs, int nargs_expected, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10) { - String message = Xot::stringf( + Xot::String s = Xot::stringf( "wrong number of arguments for %s: %d for %d", method, nargs, nargs_expected); int n[10] = {n1, n2, n3, n4, n5, n6, n7, n8, n9, n10}; for (int i = 0; i < 5 && n[i] >= 0; ++i) - message += Xot::stringf(" or %d", n[i]); + s += Xot::stringf(" or %d", n[i]); - message += "."; - argument_error(message.c_str()); + s += "."; + argument_error(file, line, s); } void - index_error (const char* format, ...) + invalid_state_error (const char* file, int line, const char* format, ...) { - XOT_STRINGF(format, message); - raise(rb_eIndexError, message.c_str()); + XOT_STRINGF(format, s); + raise(invalid_state_error_class(), Xot::error_text(file, line, s)); } void - not_implemented_error (const char* format, ...) + invalid_object_error (const char* file, int line, const char* format, ...) { - XOT_STRINGF(format, message); - raise(rb_eNotImpError, message.c_str()); + XOT_STRINGF(format, s); + raise(invalid_object_error_class(), Xot::error_text(file, line, s)); } + void + index_error (const char* file, int line, const char* format, ...) + { + XOT_STRINGF(format, s); + raise(rb_eIndexError, Xot::error_text(file, line, s)); + } void - system_error (const char* format, ...) + not_implemented_error (const char* file, int line, const char* format, ...) { - XOT_STRINGF(format, message); + XOT_STRINGF(format, s); + raise(rb_eNotImpError, Xot::error_text(file, line, s)); + } + void + system_error (const char* file, int line, const char* format, ...) + { + XOT_STRINGF(format, s); + #ifdef WIN32 - DWORD lasterror = GetLastError(); - if (lasterror != 0) - { - LPVOID msg = NULL; - DWORD flags = - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS; - if (FormatMessageA( - flags, NULL, lasterror, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR) &msg, 0, NULL)) + DWORD lasterror = GetLastError(); + if (lasterror != 0) { - String s = (LPCSTR) msg; - if (!s.empty()) message = s + ": " + message; + LPVOID msg = NULL; + DWORD flags = + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS; + if (FormatMessageA( + flags, NULL, lasterror, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &msg, 0, NULL)) + { + Xot::String m = (LPCSTR) msg; + if (!m.empty()) s += ": " + m; + } + LocalFree(msg); } - LocalFree(msg); - } #endif - raise(system_error_class(), message.c_str()); - } - - void - invalid_object_error (const char* format, ...) - { - XOT_STRINGF(format, message); - raise(invalid_object_error_class(), message.c_str()); + raise(system_error_class(), Xot::error_text(file, line, s)); } }// Rucy