本文整理汇总了C++中Exception::klass方法的典型用法代码示例。如果您正苦于以下问题:C++ Exception::klass方法的具体用法?C++ Exception::klass怎么用?C++ Exception::klass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::klass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run_file
void Environment::run_file(std::string file) {
if(!state->probe->nil_p()) state->probe->load_runtime(state, file);
std::ifstream stream(file.c_str());
if(!stream) throw std::runtime_error("Unable to open file to run");
CompiledFile* cf = CompiledFile::load(stream);
if(cf->magic != "!RBIX") throw std::runtime_error("Invalid file");
// TODO check version number
cf->execute(state);
if(!G(current_task)->exception()->nil_p()) {
// Reset the context so we can show the backtrace
// HACK need to use write barrier aware stuff?
Exception* exc = G(current_task)->exception();
G(current_task)->active(state, exc->context());
std::ostringstream msg;
msg << "exception detected at toplevel: ";
if(!exc->message()->nil_p()) {
msg << exc->message()->c_str();
}
msg << " (" << exc->klass()->name()->c_str(state) << ")";
Assertion::raise(msg.str().c_str());
}
}
示例2: state_as_object
Object* ThreadState::state_as_object(STATE) {
if(raise_reason_ == cNone && current_exception_.get()->nil_p()) return cNil;
Exception* exc = Exception::create(state);
exc->klass(state, G(exc_vm_internal));
exc->set_ivar(state, state->symbol("reason"), Fixnum::from(raise_reason_));
exc->set_ivar(state, state->symbol("destination"), destination_scope());
exc->set_ivar(state, state->symbol("throw_dest"), throw_dest());
exc->set_ivar(state, state->symbol("exception"), current_exception());
exc->set_ivar(state, state->symbol("value"), raise_value());
return exc;
}
示例3: run_file
void Environment::run_file(std::string file) {
std::ifstream stream(file.c_str());
if(!stream) {
std::string msg = std::string("Unable to open file to run: ");
msg.append(file);
throw std::runtime_error(msg);
}
CompiledFile* cf = CompiledFile::load(stream);
if(cf->magic != "!RBIX") {
std::ostringstream msg;
msg << "attempted to open a bytecode file with invalid magic identifier"
<< ": path: " << file << ", magic: " << cf->magic;
throw std::runtime_error(msg.str().c_str());
}
if((signature_ > 0 && cf->signature != signature_)
|| cf->version != version_) {
throw BadKernelFile(file);
}
cf->execute(state);
if(state->vm()->thread_state()->raise_reason() == cException) {
Exception* exc = as<Exception>(state->vm()->thread_state()->current_exception());
std::ostringstream msg;
msg << "exception detected at toplevel: ";
if(!exc->reason_message()->nil_p()) {
if(String* str = try_as<String>(exc->reason_message())) {
msg << str->c_str(state);
} else {
msg << "<non-string Exception message>";
}
} else if(Exception::argument_error_p(state, exc)) {
msg << "given "
<< as<Fixnum>(exc->get_ivar(state, state->symbol("@given")))->to_native()
<< ", expected "
<< as<Fixnum>(exc->get_ivar(state, state->symbol("@expected")))->to_native();
}
msg << " (" << exc->klass()->debug_str(state) << ")";
std::cout << msg.str() << "\n";
exc->print_locations(state);
Assertion::raise(msg.str().c_str());
}
delete cf;
}
示例4: execute_script
Object* CompiledCode::execute_script(STATE) {
state->thread_state()->clear();
Arguments args(state->symbol("script"), G(main));
scope(state, ConstantScope::create(state));
scope()->module(state, G(object));
execute(state, this, G(object), args);
/* We have to assume that this can fail before the Kernel is able to
* handle that failure, so we manually process exceptional behavior here.
*
* TODO: Fix this by ensuring normal Exceptions can be raised
*/
if(state->vm()->thread_state()->raise_reason() == cException) {
Exception* exc = as<Exception>(state->vm()->thread_state()->current_exception());
std::ostringstream msg;
msg << "exception detected at toplevel: ";
if(!exc->reason_message()->nil_p()) {
if(String* str = try_as<String>(exc->reason_message())) {
msg << str->c_str(state);
} else {
msg << "<non-string Exception message>";
}
} else if(Exception::argument_error_p(state, exc)) {
msg << "given "
<< as<Fixnum>(exc->get_ivar(state, state->symbol("@given")))->to_native()
<< ", expected "
<< as<Fixnum>(exc->get_ivar(state, state->symbol("@expected")))->to_native();
}
msg << " (" << exc->klass()->debug_str(state) << ")";
std::cout << msg.str() << "\n";
exc->print_locations(state);
Assertion::raise(msg.str().c_str());
}
return cNil;
}