/*
* This file is part of the Omni C++ framework
*
* Copyright (c) 2016, Zeriph Enterprises, LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Zeriph, Zeriph Enterprises, LLC, nor the names
* of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ZERIPH AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ZERIPH AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(OMNI_EXCEPTIONS_HPP)
#define OMNI_EXCEPTIONS_HPP 1
/*
The order of error reporting in the framework:
-Default is to throw base class
@exception.html">omni::exception (which derives from std::execption) on framework errors
-If
OMNI_NO_THROW is defined, then
OMNI_TERMINATE, which is default defined as
std::terminate(), is called
on exception instead of throwing the
@exception.html">omni::exception. Since
std::terminate calls the installed
std::terminate_handler, the Omni framework will leave it to the user to catch this if they wish
by using the
std::set_terminate function or using the
omni::application::terminate_handler::attach.
Otherwise, if no handler is installed, then
std::abort is called, in which case the framework
will catch that via the
std::signal(SIGABRT, sig_handler) function call, but only if the user made
use of the
omni::application::run function(s). If no facility is installed, nor a 'run' function called
to facilitate a
std::abort trap, then the program will crash when
std::abort is called upon
std::terminate
-If
OMNI_NO_THROW &&
OMNI_NO_TERMINATE are defined then neither
std::terminate is called nor are any
exceptions thrown. All error handling is left to external validation (i.e. false/null values being returned
or functions returning early [quick fail]). This is only recommended in the event that you're compiler does
not support any exception handling mechanism or the library used does not support any standard functions
(like terminate or abort), even in this case it is advised to change the
std::terminate call below to whatever
error mechanism your platform does support.
*/
#if defined(OMNI_NO_EXCEPT) && defined(OMNI_NO_THROW)
#if defined(OMNI_NO_TERMINATE)
// WARNING: UNDEFINED BEHAVIOUR WITHOUT ERROR HANDLING OF ANY KIND IN THE FRAMEWORK
#error
"WARNING: UNDEFINED BEHAVIOUR! Comment this line to ignore this warning"
#else
#error
"Cannot define OMNI_NO_EXCEPT and OMNI_NO_THROW without defining OMNI_NO_TERMINATE"
#endif
#endif
// define OMNI_NO_EXCEPT if you do not wish to include these
#if !defined(OMNI_NO_EXCEPT)
#include <exception>
#include <stdexcept>
#endif
#include <omni/defs/debug.hpp>
// default of 'throw @exception.html">omni::exception' on error
#if !defined(OMNI_THROW)
#define OMNI_THROW
#endif
// if no_throw, use std::terminate
#if defined(OMNI_NO_THROW)
// DEV_NOTE: exceptions (i.e. the try {} catch block) only really 'cost' more if there's an actual exception
#if defined(OMNI_THROW)
#undef OMNI_THROW
#endif
#endif
#if !defined(OMNI_TERMINATE)
#define OMNI_TERMINATE std::terminate()
#endif
// if no_terminate, then default to undefined behaviour (unless otherwise specified)
#if defined(OMNI_NO_TERMINATE) && defined(OMNI_TERMINATE)
#undef OMNI_TERMINATE
#endif
#if defined(OMNI_THROW)
#define OMNI_THROW_FW(ex) throw ex;
#else
#if defined(OMNI_TERMINATE)
#define OMNI_THROW_FW(ex) OMNI_TERMINATE;
#else
#define OMNI_THROW_FW(ex)
#endif
#endif
// OMNI_TERMINATE_FW("debug error string")
// OMNI_TERMINATEV_FW("debug error string", ret)
#if defined(OMNI_TERMINATE)
#define OMNI_TERMINATE_FW(str) OMNI_DBGE(str); OMNI_TERMINATE;
#define OMNI_TERMINATEV_FW(str, val) OMNI_DBGEV(str, val); OMNI_TERMINATE;
#else
/*
DEV_NOTE: if
std::terminate is not defined/used, then
std::abort WILL be used here; this is because
the OMNI_TERMINATE_FW macro is specifically to abort/terminate the process due to an unhandled error or
a specific framework exception, such as the
omni::sync::mutex destructor: it is undefined behaviour to
leave a mutex locked on destruction, that is, you MUST unlock a mutex before it is destroyed. In these
instances we want to make the 'undefined behaviour' defined, to which we will instigate an exception
which will crash the program if not caught. However, it's not good to throw exceptions in the destructor
of objects (due to stack unwinding), as such, we still want the program to NOT continue since that could
lead to other issues, calling terminate/abort allows the user to handle these instances vs. calling
std::exit which one would assume the program is terminating normally (vs. abnormally through an exception).
*/
#include <cstdlib> // std::abort
#define OMNI_TERMINATE_FW(str) OMNI_DBGE(str); std::abort();
#define OMNI_TERMINATEV_FW(str, val) OMNI_DBGEV(str, val); std::abort();
#endif
// OMNI_ERR_FW("debug error string", omni::execption())
// OMNI_ERRV_FW("debug error string: ", err, omni::execption())
#define OMNI_ERR_FW(str, ex) OMNI_DBGE(str); OMNI_THROW_FW(ex)
#define OMNI_ERRV_FW(str, val, ex) OMNI_DBGEV(str, val); OMNI_THROW_FW(ex)
// OMNI_ERR_RET_FW("debug error string", omni::execption())
// OMNI_ERRV_RET_FW("debug error string: ", err, omni::execption())
#define OMNI_ERR_RET_FW(str, ex) OMNI_DBGE(str); OMNI_THROW_FW(ex)
#define OMNI_ERRV_RET_FW(str, val, ex) OMNI_DBGEV(str, val); OMNI_THROW_FW(ex)
// OMNI_ERR_RETV_FW("debug error string", omni::execption(), ret)
// OMNI_ERRV_RETV_FW("debug error string: ", err, omni::execption(), ret)
#define OMNI_ERR_RETV_FW(str, ex, ret) OMNI_DBGE(str); OMNI_THROW_FW(ex)
#define OMNI_ERRV_RETV_FW(str, val, ex, ret) OMNI_DBGEV(str, val); OMNI_THROW_FW(ex)
#if defined(OMNI_THROW)
#define OMNI_TRY_FW try {
#define OMNI_CATCH_FW } catch (@exception.html">omni::exception ex) { OMNI_TERMINATE_FW(ex.what()) } catch (...) { OMNI_TERMINATE_FW(
"Unknown exception") }
#else
#define OMNI_TRY_FW
#define OMNI_CATCH_FW
#endif
#if defined(OMNI_THROW)
#include <iostream>
#include <string>
#include <sstream>
#include <omni/defs/consts.hpp>
/* DEV_NOTE: If you wish to have something other than std::terminate be called below, define OMNI_EXCEPTION_TERMINATE */
#if !defined(OMNI_EXCEPTION_TERMINATE)
// std::terminate is called when an exception happens within an exception (i.e. a null pointer reference)
#define OMNI_EXCEPTION_TERMINATE OMNI_TERMINATE;
#endif
#define OMNI_ERR_APPEND_FW(val) std::stringstream cval; cval << val; this->m_what.append(cval.str())
/* DEV_NOTE: the exception specification for 'throw()' is an implicit 'noexcept(false)' */
namespace omni {
/** exception is used to facilitate Omni Framework specific exceptions */
class exception :
virtual public std::exception
{
public:
exception()
throw() : m_what(
OMNI_GENERAL_EXCEPTION_STR) {}
explicit exception(
const char* reason)
throw() : m_what(
"")
{
if (reason) {
this->m_what.append(reason); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
}
explicit exception(
const std::string& reason)
throw() : m_what(reason) {}
exception(
const char* reason,
const char* extra)
throw() : m_what(
"")
{
if (reason) {
this->m_what.append(reason); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
if (extra) {
this->m_what.append(extra); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
}
exception(
const char* reason,
const char* extra,
int err)
throw() : m_what(
"")
{
if (reason) {
this->m_what.append(reason); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
if (extra) {
this->m_what.append(extra); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
exception(
const std::string& reason,
const std::string& extra)
throw() : m_what(reason)
{
this->m_what.append(extra);
}
exception(
const std::string& reason,
const std::string& extra,
int err)
throw() : m_what(reason)
{
this->m_what.append(extra);
OMNI_ERR_APPEND_FW(err);
}
exception(
const char* reason,
int err)
throw() : m_what(
"")
{
if (reason) {
this->m_what.append(reason); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
exception(
const std::string& reason,
int err)
throw() : m_what(reason)
{
OMNI_ERR_APPEND_FW(err);
}
exception(
const char* reason,
long err)
throw() : m_what(
"")
{
if (reason) {
this->m_what.append(reason); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
exception(
const std::string& reason,
long err)
throw() : m_what(reason)
{
OMNI_ERR_APPEND_FW(err);
}
exception(
const char* reason, std::size_t err)
throw() : m_what(
"")
{
if (reason) {
this->m_what.append(reason); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
exception(
const std::string& reason, std::size_t err)
throw() : m_what(reason)
{
OMNI_ERR_APPEND_FW(err);
}
virtual ~exception()
throw() {}
virtual void append(
const char* ex)
{
if (ex) {
this->m_what.append(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
}
virtual void append(
const std::string& ex)
{
this->m_what.append(ex);
}
virtual void append(
const char* ex,
int err)
{
if (ex) {
this->m_what.append(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
virtual void append(
const std::string& ex,
int err)
{
this->m_what.append(ex);
OMNI_ERR_APPEND_FW(err);
}
virtual void append(
const char* ex,
long err)
{
if (ex) {
this->m_what.append(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
virtual void append(
const std::string& ex,
long err)
{
this->m_what.append(ex);
OMNI_ERR_APPEND_FW(err);
}
virtual void append(
const char* ex, std::size_t err)
{
if (ex) {
this->m_what.append(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
virtual void append(
const std::string& ex, std::size_t err)
{
this->m_what.append(ex);
OMNI_ERR_APPEND_FW(err);
}
virtual const char* what()
const throw() {
return this->m_what.c_str(); }
virtual void seterr(
const char* ex)
{
if (ex) {
this->m_what =
std::string(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
}
virtual void seterr(
const std::string& ex) {
this->m_what = ex; }
virtual void seterr(
const char* ex,
int err)
{
if (ex) {
this->m_what =
std::string(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
virtual void seterr(
const std::string& ex,
int err)
{
this->m_what = ex;
OMNI_ERR_APPEND_FW(err);
}
virtual void seterr(
const char* ex,
long err)
{
if (ex) {
this->m_what =
std::string(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
virtual void seterr(
const std::string& ex,
long err)
{
this->m_what = ex;
OMNI_ERR_APPEND_FW(err);
}
virtual void seterr(
const char* ex, std::size_t err)
{
if (ex) {
this->m_what =
std::string(ex); }
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
OMNI_ERR_APPEND_FW(err);
}
virtual void seterr(
const std::string& ex, std::size_t err)
{
std::stringstream cval(ex);
cval << err;
this->m_what = cval.str();
}
operator std::string()
const
{
return this->m_what;
}
operator std::wstring()
const
{
std::wstringstream o;
o <<
this->m_what.c_str();
return o.str();
}
friend std::ostream&
operator<<(
std::ostream& s,
const @exception.html">omni::exception& e)
{
s << e.m_what;
return s;
}
friend std::wostream&
operator<<(
std::wostream& s,
const @exception.html">omni::exception& e)
{
s << e.m_what.c_str();
return s;
}
protected:
std::string m_what;
};
/** An invalid delegate function pointer was specified and called */
class invalid_delegate :
virtual public @exception.html">omni::exception
{
public:
invalid_delegate() :
@exception.html">omni::exception(
OMNI_INVALID_DELEGATE_FUNC_STR) {}
};
/** An invalid type cast was detected on an Omni Framework object */
class invalid_type_cast :
virtual public @exception.html">omni::exception
{
public:
invalid_type_cast() :
@exception.html">omni::exception(
OMNI_INVALID_CAST_STR) {}
};
/** An invalid type was detected on a template parameter that only takes certain types */
class invalid_template_type :
virtual public @exception.html">omni::exception
{
public:
invalid_template_type() :
@exception.html">omni::exception(
OMNI_INVALID_TEMPLATE_STR) {}
};
/** This exception is specific to the Omni Framework, it is here so as not to be confused with the std::out_of_range exception. */
class index_out_of_range :
virtual public @exception.html">omni::exception
{
public:
index_out_of_range() :
@exception.html">omni::exception(
OMNI_INDEX_OOR_STR) {}
index_out_of_range(
const char* msg, std::size_t idx) :
@exception.html">omni::exception(msg, idx) {}
index_out_of_range(
const std::string& msg, std::size_t idx) :
@exception.html">omni::exception(msg, idx) {}
explicit index_out_of_range(
const char* var) :
@exception.html">omni::exception(
OMNI_INDEX_OOR_STR) {
if (var) {
this->m_what.append(
": ");
this->m_what.append(var);
}
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
}
explicit index_out_of_range(
const std::string& var) :
@exception.html">omni::exception(
OMNI_INDEX_OOR_STR) {
this->m_what.append(
": ");
this->m_what.append(var);
}
explicit index_out_of_range(std::size_t idx) :
@exception.html">omni::exception(
OMNI_INDEX_OOR_STR) {
this->m_what.append(
": ");
OMNI_ERR_APPEND_FW(idx);
}
};
/** A null pointer was specified to be used which would cause undefined behaviour */
class null_pointer_exception :
virtual public @exception.html">omni::exception
{
public:
null_pointer_exception() :
@exception.html">omni::exception(
OMNI_NULL_REF_STR) {}
explicit null_pointer_exception(
const char* variable) :
@exception.html">omni::exception(
OMNI_NULL_REF_STR) {
if (variable) {
this->m_what.append(
" on ");
this->m_what.append(variable);
}
else {
OMNI_DBGE(
OMNI_NULL_PTR_STR);
OMNI_EXCEPTION_TERMINATE
}
}
explicit null_pointer_exception(
const std::string& variable) :
@exception.html">omni::exception(
OMNI_NULL_REF_STR) {
this->m_what.append(
" on ");
this->m_what.append(variable);
}
};
/** A system clock error occurred */
class clock_exception :
virtual public @exception.html">omni::exception
{
public:
clock_exception() :
@exception.html">omni::exception(
OMNI_ERR_GET_TIME_STR) {}
explicit clock_exception(
int err) :
@exception.html">omni::exception(
OMNI_ERR_GET_TIME_STR,
": ", err) {}
};
/** A system exception occurred on the mutex object */
class mutex_system_exception :
virtual public @exception.html">omni::exception
{
public:
mutex_system_exception() :
@exception.html">omni::exception(
OMNI_ERR_MUTEX_STR) {}
explicit mutex_system_exception(
int er) :
@exception.html">omni::exception(
OMNI_ERR_MUTEX_STR,
": ", er) {}
explicit mutex_system_exception(
long er) :
@exception.html">omni::exception(
OMNI_ERR_MUTEX_STR,
": ", er) {}
explicit mutex_system_exception(
const char* msg) :
@exception.html">omni::exception(msg) {}
mutex_system_exception(
const char* msg,
int er) :
@exception.html">omni::exception(msg, er) {}
mutex_system_exception(
const char* msg,
long er) :
@exception.html">omni::exception(msg, er) {}
};
/** The system mutex was left in an undefined state (as in calling mutex_destroy on a mutex that is still locked) */
class invalid_mutex_state :
virtual public omni::mutex_system_exception
{
public:
invalid_mutex_state() :
omni::mutex_system_exception(
OMNI_ERR_MTX_STATE_STR) {}
};
/** An attempt was made to unlock a non locked mutex */
class mutex_unlock_exception :
virtual public omni::mutex_system_exception
{
public:
mutex_unlock_exception() :
omni::mutex_system_exception(
OMNI_ERR_MTX_UNLOCKED_STR) {}
};
/** Unlock was called from non-owning thread */
class mutex_owning_thread_exception :
virtual public omni::mutex_system_exception
{
public:
mutex_owning_thread_exception() :
omni::mutex_system_exception(
OMNI_ERR_MTX_OWNER_STR) {}
};
/** A system error occurred on the semaphore */
class semaphore_system_exception :
virtual public @exception.html">omni::exception
{
public:
semaphore_system_exception() :
@exception.html">omni::exception(
OMNI_ERR_SEMAPHORE_STR) {}
explicit semaphore_system_exception(
int er) :
@exception.html">omni::exception(
OMNI_ERR_SEMAPHORE_STR,
": ", er) {}
explicit semaphore_system_exception(
long er) :
@exception.html">omni::exception(
OMNI_ERR_SEMAPHORE_STR,
": ", er) {}
explicit semaphore_system_exception(
const char* msg) :
@exception.html">omni::exception(msg) {}
semaphore_system_exception(
const char* msg,
int er) :
@exception.html">omni::exception(msg, er) {}
semaphore_system_exception(
const char* msg,
long er) :
@exception.html">omni::exception(msg, er) {}
};
/** An attempt was made to release a semaphore in a non-wait state */
class semaphore_release_exception :
virtual public omni::semaphore_system_exception
{
public:
semaphore_release_exception() :
omni::semaphore_system_exception(
OMNI_ERR_SEM_STATE_STR) {}
};
/** A system error occurred on the spin_lock object */
class spin_lock_exception :
virtual public @exception.html">omni::exception
{
public:
spin_lock_exception() :
@exception.html">omni::exception(
OMNI_ERR_SPIN_OBJ_STR) {}
spin_lock_exception(
int err) :
@exception.html">omni::exception(
OMNI_ERR_SPIN_OBJ_STR,
": ", err) {}
};
/** A system error occurred on the conditional object */
class conditional_exception :
virtual public @exception.html">omni::exception
{
public:
conditional_exception() :
@exception.html">omni::exception(
OMNI_ERR_COND_OBJ_STR) {}
conditional_exception(
int err) :
@exception.html">omni::exception(
OMNI_ERR_COND_OBJ_STR,
": ", err) {}
};
/** An active wait was pending on a call to semaphore destruction */
class active_wait_exception :
virtual public @exception.html">omni::exception
{
public:
active_wait_exception() :
@exception.html">omni::exception(
OMNI_ERR_WAIT_STR) {}
};
/** An invalid release count was specified on the semaphore */
class invalid_release_count :
virtual public omni::semaphore_system_exception
{
public:
invalid_release_count() :
omni::semaphore_system_exception(
OMNI_ERR_RELEASE_STR) {}
};
/** An error occurred on a thread object */
class thread_exception :
virtual public @exception.html">omni::exception
{
public:
thread_exception() :
@exception.html">omni::exception(
OMNI_ERR_THREAD_STR) {}
thread_exception(
std::string msg,
int perr) :
@exception.html">omni::exception(msg, perr) {}
thread_exception(
std::string msg, std::size_t perr) :
@exception.html">omni::exception(msg, perr) {}
thread_exception(
const char* msg,
int perr) :
@exception.html">omni::exception(msg, perr) {}
thread_exception(
const char* msg, std::size_t perr) :
@exception.html">omni::exception(msg, perr) {}
explicit thread_exception(
const std::string& msg) :
@exception.html">omni::exception(msg) {}
explicit thread_exception(
const char* msg) :
@exception.html">omni::exception(msg) {}
explicit thread_exception(
int perr) :
@exception.html">omni::exception(
OMNI_ERR_THREAD_STR,
": ", perr) {
}
explicit thread_exception(std::size_t perr) :
@exception.html">omni::exception(
OMNI_ERR_THREAD_STR,
": ", perr) {
}
};
/** An invalid state was specified for the thread object */
class invalid_thread_state :
virtual public omni::thread_exception
{
public:
invalid_thread_state() :
omni::thread_exception(
OMNI_INVALID_THREAD_STATE_STR) {}
};
/** An invalid thread handle was specified */
class invalid_thread_handle :
virtual public omni::thread_exception
{
public:
invalid_thread_handle() :
omni::thread_exception(
OMNI_INVALID_THREAD_HANDLE_STR) {}
};
/** An invalid thread option was specified */
class invalid_thread_option :
virtual public omni::thread_exception
{
public:
invalid_thread_option() :
omni::thread_exception(
OMNI_INVALID_OPTION_STR) {}
explicit invalid_thread_option(std::size_t var) :
@exception.html">omni::exception(
OMNI_INVALID_OPTION_STR,
": ", var) {}
};
/** An invalid thread start type was specified */
class invalid_thread_start_type :
virtual public omni::thread_exception
{
public:
invalid_thread_start_type() :
omni::thread_exception(
OMNI_INVALID_THREAD_START_TYPE_STR) {}
};
/** An operation was made on a thread in an already started state and cannot be called once running */
class thread_running_exception :
virtual public omni::invalid_thread_state
{
public:
thread_running_exception() :
omni::thread_exception(
OMNI_THREAD_STARTED_STR) {}
};
/** An error occurred on a threadpool object */
class threadpool_exception :
virtual public @exception.html">omni::exception
{
public:
threadpool_exception() :
@exception.html">omni::exception(
OMNI_ERR_THREADPOOL_STR) {}
explicit threadpool_exception(
const std::string& msg) :
@exception.html">omni::exception(msg) {}
explicit threadpool_exception(
const char* msg) :
@exception.html">omni::exception(msg) {}
};
/** An internal state error occurred */
class threadpool_state_exception :
virtual public omni::threadpool_exception
{
public:
threadpool_state_exception() :
omni::threadpool_exception(
OMNI_ERR_STATE_STR) {}
};
/** An error occurred and the threadpool could not acquire a thread */
class threadpool_thread_exception :
virtual public omni::threadpool_exception
{
public:
threadpool_thread_exception() :
omni::threadpool_exception(
OMNI_ERR_ACQUIRE_STR) {}
};
/** An invalid size was specified for the threadpool object */
class invalid_threadpool_size :
virtual public omni::threadpool_exception
{
public:
invalid_threadpool_size() :
omni::threadpool_exception(
OMNI_INVALID_SIZE_STR) {}
};
/** An exception occurred on the version object */
class version_exception :
virtual public @exception.html">omni::exception
{
public:
version_exception() :
@exception.html">omni::exception(
OMNI_INVALID_VERSION_STR) {}
};
/** An application exception happened within the omni::application namespace */
class application_exception :
virtual public @exception.html">omni::exception
{
public:
application_exception() :
@exception.html">omni::exception(
OMNI_ERR_APPEX_STR) {}
application_exception(
const char* msg,
int er) :
@exception.html">omni::exception(msg, er) {}
application_exception(
const char* msg,
long er) :
@exception.html">omni::exception(msg, er) {}
explicit application_exception(
const char* msg) :
@exception.html">omni::exception(msg) {}
explicit application_exception(
int er) :
@exception.html">omni::exception(
OMNI_ERR_APPEX_STR,
": ", er) {
}
explicit application_exception(
long er) :
@exception.html">omni::exception(
OMNI_ERR_APPEX_STR,
": ", er) {
}
};
/** An omni::application context is already running (i.e. omni::application::run was called twice) */
class context_running_exception :
virtual public omni::application_exception
{
public:
context_running_exception() :
omni::application_exception(
OMNI_APP_RUNNING_STR) {}
};
/** A general environment exception occurred */
class environment_exception :
virtual public @exception.html">omni::exception
{
public:
environment_exception() :
@exception.html">omni::exception(
OMNI_ERR_ENVEX_STR) {}
explicit environment_exception(std::size_t err) :
@exception.html">omni::exception(
OMNI_ERR_ENVEX_STR,
": ", err) {}
};
/** An empty environment variable name was specified */
class name_empty_exception :
virtual public omni::environment_exception
{
public:
name_empty_exception() :
@exception.html">omni::exception(
OMNI_ERR_NAME_STR) {}
};
/** An error occurred on the system pipe */
class pipe_exception :
virtual public omni::environment_exception
{
public:
pipe_exception() :
@exception.html">omni::exception(
OMNI_ERR_PIPE_STR) {}
};
/** A system error occurred on the string */
class string_exception :
virtual public @exception.html">omni::exception
{
public:
string_exception() :
@exception.html">omni::exception(
OMNI_ERR_STROBJ_STR) {}
explicit string_exception(
const char* msg) :
@exception.html">omni::exception(msg) {}
};
/** The specified string does not contain a valid binary number */
class invalid_binary_format :
virtual public omni::string_exception
{
public:
invalid_binary_format() :
omni::string_exception(
OMNI_STRING_INVALID_FORMAT_STR) {}
};
/** The binary string length is greater than sizeof conversion unit */
class invalid_binary_size :
virtual public omni::string_exception
{
public:
invalid_binary_size() :
omni::string_exception(
OMNI_STRING_INVALID_SIZE_STR) {}
};
/** Invalid size written */
class invalid_size_written :
virtual public omni::string_exception
{
public:
invalid_size_written() :
omni::string_exception(
OMNI_ERR_SIZE_STR) {}
};
/** An error occurred on the stopwatch */
class stopwatch_exception :
virtual public @exception.html">omni::exception
{
public:
stopwatch_exception() :
@exception.html">omni::exception(
OMNI_ERR_STOPWATCH_STR) {}
stopwatch_exception(
const char* msg,
int er) :
@exception.html">omni::exception(msg, er) {}
stopwatch_exception(
const char* msg,
long er) :
@exception.html">omni::exception(msg ,er) {}
explicit stopwatch_exception(
const char* msg) :
@exception.html">omni::exception(msg) {}
explicit stopwatch_exception(
int er) :
@exception.html">omni::exception(
OMNI_ERR_STOPWATCH_STR,
": ", er) {
}
explicit stopwatch_exception(
long er) :
@exception.html">omni::exception(
OMNI_ERR_STOPWATCH_STR,
": ", er) {
}
};
}
// namespace omni
#undef OMNI_ERR_APPEND_FW
#endif // OMNI_NO_THROW
#endif // OMNI_EXCEPTIONS_HPP