Пример #1
0
  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
0
void 
CompilerOutputter::printFailureMessage( TestFailure *failure )
{
  m_stream  <<  std::endl;
  Exception *thrownException = failure->thrownException();
  m_stream  << thrownException->message().shortDescription()  <<  std::endl;

  std::string message = thrownException->message().details();
  if ( m_wrapColumn > 0 )
    message = StringTools::wrap( message, m_wrapColumn );

  m_stream  <<  message  <<  std::endl;
}
Пример #3
0
  void Environment::run_file(std::string path) {
    std::stringstream stream;
    std::ifstream file(path.c_str(), std::ios::ate|std::ios::binary);

    if(!file) {
      std::string msg = std::string("Unable to open file to run: ");
      msg.append(path);
      throw std::runtime_error(msg);
    }

    std::streampos length = file.tellg();
    std::vector<char> buffer(length);
    file.seekg(0, std::ios::beg);
    file.read(&buffer[0], length);
    stream.rdbuf()->pubsetbuf(&buffer[0], length);

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") throw std::runtime_error("Invalid file");
    if((signature_ > 0 && cf->signature != signature_)
        || cf->version != version_) {
      throw BadKernelFile(path);
    }

    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->message()->nil_p()) {
        if(String* str = try_as<String>(exc->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
0
  Exception* Exception::make_exception(STATE, Class* exc_class, const char* message) {
    Exception* exc = state->new_object<Exception>(exc_class);

    exc->message(state, String::create(state, message));

    return exc;
  }
Пример #5
0
  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) {
      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") throw std::runtime_error("Invalid file");
    if(signature_ > 0) {
      if(cf->version != signature_) throw BadKernelFile(file);
    }

    /** @todo Redundant? CompiledFile::execute() does this. --rue */
    state->thread_state()->clear_exception(true);

    // TODO check version number
    cf->execute(state);

    if(state->thread_state()->raise_reason() == cException) {
      Exception* exc = as<Exception>(state->thread_state()->raise_value());
      std::ostringstream msg;

      msg << "exception detected at toplevel: ";
      if(!exc->message()->nil_p()) {
        if(String* str = try_as<String>(exc->message())) {
          msg << str->c_str();
        } 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()->name()->c_str(state) << ")";
      std::cout << msg.str() << "\n";
      exc->print_locations(state);
      Assertion::raise(msg.str().c_str());
    }

    delete cf;
  }
Пример #6
0
  void Exception::Info::show(STATE, Object* self, int level) {
    Exception* exc = as<Exception>(self);

    class_header(state, self);
    indent_attribute(++level, "message"); exc->message()->show(state, level);
    indent_attribute(level, "locations"); exc->locations()->show_simple(state, level);
    close_body(level);
  }
Пример #7
0
void RequestError::exception(Request* request, Exception& e)
{
	int code = 500;
	if (e.type() == "NotFound")
		code = 404;
	else if (e.type() == "Forbidden")
		code = 403;

	if (code == 404)
		System::log("NotFound", e.message(), request->ip());
	else if (code == 403)
		System::log("Forbidden", e.message(), System::Warning, request->ip());
	else
		System::log("Exceptions",
		            String("“%1” exception: %2.").format({e.type(), e.message()}),
		            System::Warning, request->ip());

#ifndef DEBUG
	if (!request->headersSent())
		request->setStatus(code);
	Template* tpl = new Template("Errors/" + String(code) + ".html",
	                             nullptr, request);
	tpl->render();
	delete tpl;
	return;
#endif

	try
	{
		View tpl = new Template("Sys::Exception.html", nullptr, request);

		tpl["exceptionName"] = e.type();
		tpl["exceptionMessage"] = e.htmlMessage();
		tpl["webcppVersion"] = System::get()->version();
		tpl["serverName"] = request->env("SERVER_NAME", "");
		loadStackTrace(e, dynamic_cast<Template*>(*tpl));

		if (!request->headersSent())
			request->setStatus(500);
		tpl->render();
	}
	catch (const Exception& e2)
	{ fallbackErrorPage(request, e, e2.type()); }
	catch (const std::exception& e2)
	{ fallbackErrorPage(request, e, typeid(e2).name()); }
}
Пример #8
0
Exception::Exception(Exception const& e)
        : m_module(copy_string(e.m_module))
        , m_code(e.m_code)
        , m_message(copy_string(e.m_message ? e.m_message : e.message()))
        , m_args(0)
        , m_num_args(0)
        , m_next(e.m_next ? new /*(nothrow)*/ Exception(*e.m_next) :  0) // FIXME re-enable nothrow
{
    set_arguments(e.m_args, e.m_num_args);
}
Пример #9
0
Message::Message(const Exception& e, DistributionRealm realm, 
		 PayloadSignificance sig, bool highlight) throw():
  m_hostname(s_this_hostname), m_origin(MO_LOCAL), m_zone(-1),
  m_program(s_this_program), m_title(e.title()), m_realm(realm), 
  m_significance(sig), m_message_oss(e.message()), m_details_oss(e.details()), 
  m_function(e.function(highlight)), m_time()
{
  m_time.tv_sec=e.time().tv_sec;
  m_time.tv_usec=e.time().tv_usec;
}
Пример #10
0
/******************************************************************************
* Handler function for exceptions used in GUI mode.
******************************************************************************/
void Application::guiExceptionHandler(const Exception& exception)
{
	exception.logError();
	QMessageBox msgbox;
	msgbox.setWindowTitle(tr("Error - %1").arg(QCoreApplication::applicationName()));
	msgbox.setStandardButtons(QMessageBox::Ok);
	msgbox.setText(exception.message());
	msgbox.setIcon(QMessageBox::Critical);
	if(exception.messages().size() > 1) {
		QString detailText;
		for(int i = 1; i < exception.messages().size(); i++)
			detailText += exception.messages()[i] + "\n";
		msgbox.setDetailedText(detailText);
	}
	msgbox.exec();
}
Пример #11
0
  Exception* Exception::make_errno_exception(STATE, Class* exc_class, Object* reason) {
    Exception* exc = state->new_object<Exception>(exc_class);

    String* message = (String*)reason;
    if(String* str = try_as<String>(exc_class->get_const(state, "Strerror"))) {
      str = str->string_dup(state);
      if(String* r = try_as<String>(reason)) {
        str->append(state, " - ");
        message = str->append(state, r);
      } else {
        message = str;
      }
    }
    exc->message(state, message);

    exc->set_ivar(state, state->symbol("@errno"),
                  exc_class->get_const(state, "Errno"));

    return exc;
  }
Пример #12
0
void MainWindow::showErrorMessage(Exception &ex) {
    showErrorMessage(ex.message());
}
Пример #13
0
  static Handle exc_message(State& S, Handle recv, Arguments& args) {
    Exception* exc = recv->exception();

    return handle(S, exc->message());
  }
Пример #14
0
Exception::Exception(Exception &e)
    : m_str()
{
    m_str.clear();
    m_str << e.message();
}
Пример #15
0
void ExceptionTest::testConstructorEmpty() {
    Exception exception;

    QCOMPARE(exception.what(), "");
    QCOMPARE(exception.message(), QString(""));
}