Sha256: e0de2776c42d5786cd8895a9aff8271d49d5626bb26af50e59ffb501b9de76db

Contents?: true

Size: 1.8 KB

Versions: 20

Compression:

Stored size: 1.8 KB

Contents

#include "rucy.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

20 entries across 20 versions & 1 rubygems

Version Path
rucy-0.1.28 .doc/ext/rucy/exception.cpp
rucy-0.1.27 .doc/ext/rucy/exception.cpp
rucy-0.1.26 .doc/ext/rucy/exception.cpp
rucy-0.1.25 .doc/ext/rucy/exception.cpp
rucy-0.1.24 .doc/ext/rucy/exception.cpp
rucy-0.1.23 .doc/ext/rucy/exception.cpp
rucy-0.1.22 .doc/ext/rucy/exception.cpp
rucy-0.1.21 .doc/ext/rucy/exception.cpp
rucy-0.1.20 .doc/ext/rucy/exception.cpp
rucy-0.1.18 .doc/ext/rucy/exception.cpp
rucy-0.1.16 .doc/ext/rucy/exception.cpp
rucy-0.1.15 .doc/ext/rucy/exception.cpp
rucy-0.1.14 .doc/ext/rucy/exception.cpp
rucy-0.1.13 .doc/ext/rucy/exception.cpp
rucy-0.1.12 .doc/ext/rucy/exception.cpp
rucy-0.1.11 .doc/ext/rucy/exception.cpp
rucy-0.1.10 .doc/ext/rucy/exception.cpp
rucy-0.1.9 .doc/ext/rucy/exception.cpp
rucy-0.1.8 .doc/ext/rucy/exception.cpp
rucy-0.1.7 .doc/ext/rucy/exception.cpp