mrbc_raise function supports the 'msg' argument is NULL.
@@ -139,15 +139,19 @@ void mrbc_exception_delete(mrbc_value *value)
/*! raise exception
@param vm pointer to VM.
- @param exc_cls pointer to Exception class.
- @param msg message.
+ @param exc_cls pointer to Exception class or NULL.
+ @param msg message or NULL.
@note (usage) mrbc_raise(vm, MRBC_CLASS(TypeError), "message here.");
*/
void mrbc_raise( struct VM *vm, struct RClass *exc_cls, const char *msg )
{
if( vm ) {
- vm->exception = mrbc_exception_new( vm, exc_cls ? exc_cls : MRBC_CLASS(RuntimeError), msg, strlen(msg) );
+ struct RClass *cls = exc_cls ? exc_cls : MRBC_CLASS(RuntimeError);
+ const char msg_len = msg ? strlen(msg) : 0;
+
+ vm->exception = mrbc_exception_new( vm, cls, msg, msg_len );
vm->flag_preemption = 2;
+
} else {
mrbc_printf("Exception: %s (%s)\n", msg ? msg : mrbc_symid_to_str(exc_cls->sym_id), mrbc_symid_to_str(exc_cls->sym_id));
}
