Sha256: ca1bf8bbd8f82fa6442b054116572a9b6b453c23e8327a6c958fa6c6a2759220

Contents?: true

Size: 1.8 KB

Versions: 22

Compression:

Stored size: 1.8 KB

Contents

#include "defs.h"


using namespace Rucy;


/*
	raise ruby's exception.
*/
static
VALUE raise_ruby_exception(VALUE self)
{
	throw RubyException(rb_eStandardError, "raise_ruby_exception");
}

/*
	raise in eval.
*/
static
VALUE raise_in_eval(VALUE self)
{
	eval("raise 'raise_in_eval'");
}

/*
	throw nothing.
*/
static
VALUE throw_nothing(VALUE self)
{
	throw;
}

/*
	throw std::exception.
*/
static
VALUE throw_std_exception(VALUE self)
{
	throw std::exception();
}

/*
	throw std::runtime_error.
*/
static
VALUE throw_std_runtime_error(VALUE self)
{
	throw std::runtime_error("std::runtime_error");
}

struct MyException : public std::runtime_error
{
	MyException() : runtime_error("") {}
};

/*
	throw custom exception class.
*/
static
VALUE throw_custom_exception(VALUE self)
{
	throw MyException();
}

/*
	throw std::string.
*/
static
VALUE throw_std_string(VALUE self)
{
	throw std::string("std::string");
}

/*
	throw char*.
*/
static
VALUE throw_cstring(VALUE self)
{
	throw "cstring";
}


void
Init_exception ()
{
	Module mRucy = rb_define_module("Rucy");
	Module mTester = rb_define_module_under(mRucy, "Tester");

	rb_define_method(mTester, "raise_ruby_exception", RUBY_METHOD_FUNC(raise_ruby_exception), 0);
	rb_define_method(mTester, "raise_in_eval", RUBY_METHOD_FUNC(raise_in_eval), 0);
	rb_define_method(mTester, "throw_nothing", RUBY_METHOD_FUNC(throw_nothing), 0);
	rb_define_method(mTester, "throw_std_exception", RUBY_METHOD_FUNC(throw_std_exception), 0);
	rb_define_method(mTester, "throw_std_runtime_error", RUBY_METHOD_FUNC(throw_std_runtime_error), 0);
	rb_define_method(mTester, "throw_custom_exception", RUBY_METHOD_FUNC(throw_custom_exception), 0);
	rb_define_method(mTester, "throw_std_string", RUBY_METHOD_FUNC(throw_std_string), 0);
	rb_define_method(mTester, "throw_cstring", RUBY_METHOD_FUNC(throw_cstring), 0);
}

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rucy-0.3.3 .doc/ext/rucy/exception.cpp
rucy-0.3.2 .doc/ext/rucy/exception.cpp
rucy-0.3.1 .doc/ext/rucy/exception.cpp
rucy-0.3 .doc/ext/rucy/exception.cpp
rucy-0.2.1 .doc/ext/rucy/exception.cpp
rucy-0.2 .doc/ext/rucy/exception.cpp
rucy-0.1.44 .doc/ext/rucy/exception.cpp
rucy-0.1.43 .doc/ext/rucy/exception.cpp
rucy-0.1.42 .doc/ext/rucy/exception.cpp
rucy-0.1.41 .doc/ext/rucy/exception.cpp
rucy-0.1.40 .doc/ext/rucy/exception.cpp
rucy-0.1.39 .doc/ext/rucy/exception.cpp
rucy-0.1.38 .doc/ext/rucy/exception.cpp
rucy-0.1.37 .doc/ext/rucy/exception.cpp
rucy-0.1.36 .doc/ext/rucy/exception.cpp
rucy-0.1.35 .doc/ext/rucy/exception.cpp
rucy-0.1.34 .doc/ext/rucy/exception.cpp
rucy-0.1.33 .doc/ext/rucy/exception.cpp
rucy-0.1.32 .doc/ext/rucy/exception.cpp
rucy-0.1.31 .doc/ext/rucy/exception.cpp