1 /* -----------------------------------------------------------------------------
3 * ----------------------------------------------------------------------------- */
6 /* Define some additional error types */
7 #define SWIG_ObjectPreviouslyDeletedError -100
10 /* Define custom exceptions for errors that do not map to existing Ruby
11 exceptions. Note this only works for C++ since a global cannot be
12 initialized by a funtion in C. For C, fallback to rb_eRuntimeError.*/
15 getNullReferenceError(void) {
17 static VALUE rb_eNullReferenceError ;
20 rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
22 return rb_eNullReferenceError;
26 getObjectPreviouslyDeletedError(void) {
28 static VALUE rb_eObjectPreviouslyDeleted ;
31 rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
33 return rb_eObjectPreviouslyDeleted;
38 SWIG_Ruby_ErrorType(int SWIG_code) {
41 case SWIG_MemoryError:
42 type = rb_eNoMemError;
47 case SWIG_RuntimeError:
48 type = rb_eRuntimeError;
51 type = rb_eIndexError;
56 case SWIG_DivisionByZero:
57 type = rb_eZeroDivError;
59 case SWIG_OverflowError:
60 type = rb_eRangeError;
62 case SWIG_SyntaxError:
63 type = rb_eSyntaxError;
68 case SWIG_SystemError:
71 case SWIG_AttributeError:
72 type = rb_eRuntimeError;
74 case SWIG_NullReferenceError:
75 type = getNullReferenceError();
77 case SWIG_ObjectPreviouslyDeletedError:
78 type = getObjectPreviouslyDeletedError();
80 case SWIG_UnknownError:
81 type = rb_eRuntimeError;
84 type = rb_eRuntimeError;
90 /* This function is called when a user inputs a wrong argument to
94 const char* Ruby_Format_TypeError( const char* msg,
105 str = rb_str_new2(msg);
109 str = rb_str_new(NULL, 0);
112 str = rb_str_cat2( str, "Expected argument " );
113 sprintf( buf, "%d of type ", argn-1 );
114 str = rb_str_cat2( str, buf );
115 str = rb_str_cat2( str, type );
116 str = rb_str_cat2( str, ", but got " );
117 str = rb_str_cat2( str, rb_obj_classname(input) );
118 str = rb_str_cat2( str, " " );
119 asStr = rb_inspect(input);
120 if ( RSTRING_LEN(asStr) > 30 )
122 str = rb_str_cat( str, StringValuePtr(asStr), 30 );
123 str = rb_str_cat2( str, "..." );
127 str = rb_str_append( str, asStr );
132 str = rb_str_cat2( str, "\n\tin SWIG method '" );
133 str = rb_str_cat2( str, name );
134 str = rb_str_cat2( str, "'" );
137 return StringValuePtr( str );
140 /* This function is called when an overloaded method fails */
142 void Ruby_Format_OverloadedError(
146 const char* prototypes
149 const char* msg = "Wrong # of arguments";
150 if ( argc <= maxargs ) msg = "Wrong arguments";
151 rb_raise(rb_eArgError,"%s for overloaded method '%s'.\n"
152 "Possible C/C++ prototypes are:\n%s",
153 msg, method, prototypes);