Esempio n. 1
0
DbException::DbException(const DbException &that)
:	__DB_STD(exception)()
,	what_(dupString(that.what_))
,	err_(that.err_)
,	dbenv_(0)
{
}

DbException &DbException::operator = (const DbException &that)
{
	if (this != &that) {
		err_ = that.err_;
		delete [] what_;
		what_ = dupString(that.what_);
	}
	return (*this);
}

void DbException::describe(const char *prefix, const char *description)
{
	char *msgbuf, *p, *end;

	msgbuf = new char[MAX_DESCRIPTION_LENGTH];
	p = msgbuf;
	end = msgbuf + MAX_DESCRIPTION_LENGTH - 1;

	if (prefix != NULL) {
		strncpy(p, prefix, (p < end) ? end - p: 0);
		p += strlen(prefix);
		strncpy(p, ": ", (p < end) ? end - p: 0);
		p += 2;
	}
	if (description != NULL) {
		strncpy(p, description, (p < end) ? end - p: 0);
		p += strlen(description);
		if (err_ != 0) {
			strncpy(p, ": ", (p < end) ? end - p: 0);
			p += 2;
		}
	}
	if (err_ != 0) {
		strncpy(p, db_strerror(err_), (p < end) ? end - p: 0);
		p += strlen(db_strerror(err_));
	}

	/*
	 * If the result was too long, the buffer will not be null-terminated,
	 * so we need to fix that here before duplicating it.
	 */
	if (p >= end)
		*end = '\0';

	what_ = dupString(msgbuf);
	delete [] msgbuf;
}
Esempio n. 2
0
    void GlobalExceptionHandler::terminate() throw()
    {
      // add cerr to the log stream
      // and write all available information on
      // the exception to the log stream (potentially with an assigned file!)
      // and cerr

      std::cout << std::endl;
      std::cout << "---------------------------------------------------" << std::endl;
      std::cout << "FATAL: uncaught exception!" << std::endl;
      std::cout << "---------------------------------------------------" << std::endl;
      if ((line_() != -1) && (name_() != "unknown"))
      {
        std::cout << "last entry in the exception handler: " << std::endl;
        std::cout << "exception of type " << name_().c_str() << " occured in line "
                  << line_() << ", function " << function_() << " of " << file_().c_str() << std::endl;
        std::cout << "error message: " << what_().c_str() << std::endl;
      }
      std::cout << "---------------------------------------------------" << std::endl;

#ifndef OPENMS_WINDOWSPLATFORM
      // if the environment variable declared in OPENMS_CORE_DUMP_ENVNAME
      // is set, provoke a core dump (this is helpful to get a stack traceback)
      if (getenv(OPENMS_CORE_DUMP_ENVNAME) != 0)
      {
#ifdef OPENMS_HAS_KILL
        std::cout << "dumping core file.... (to avoid this, unset " << OPENMS_CORE_DUMP_ENVNAME
                  << " in your environment)" << std::endl;
        // provoke a core dump
        kill(getpid(), SIGSEGV);
#endif
      }
#endif

      // otherwise exit as default terminate() would:
      abort();
    }