#include <assert.h>
#include <cstdint>
#include <exception>
+#include <stdexcept>
#include <string>
#include <memory>
namespace cds {
- /// Base of all exceptions in the library
- class Exception: public std::exception
- {
- protected:
- std::string m_strMsg ; ///< Exception message
- public:
- /// Create empty exception
- Exception()
- {}
- /// Create exception with message
- explicit Exception( const char * pszMsg )
- : m_strMsg( pszMsg )
- {}
- /// Create exception with message
- explicit Exception( const std::string& strMsg )
- :m_strMsg( strMsg )
- {}
-
- /// Destructor
- virtual ~Exception() throw()
- {}
-
- /// Return exception message
- virtual const char * what( ) const throw()
- {
- return m_strMsg.c_str();
- }
- };
-
/// any_type is used as a placeholder for auto-calculated type (usually in \p rebind templates)
struct any_type {};
typedef cds::opt::none debug_bound_checking;
#endif
- /// %Exception of \ref strong_bound_checking bound checker
- class bound_checker_exception: public std::exception
+ /// Exception of \ref strong_bound_checking bound checker
+ class bound_checker_exception: public std::out_of_range
{
//@cond
public:
- virtual const char * what() const throw()
- {
- return "Memory bound checking violation";
- }
+ bound_checker_exception()
+ : std::out_of_range( "Memory bound checking violation" )
+ {}
//@endcond
};
- /// %Exception throwing bound checker
+ /// Exception throwing bound checker
/**
This is one of value of opt::check_bounds option for Michael's \ref Heap memory allocator.
It is intended for debug and release mode.
throw bound_checker_exception();
}
}
-
//@endcond
};
#ifndef __CDS_THREADING_DETAILS_PTHREAD_MANAGER_H
#define __CDS_THREADING_DETAILS_PTHREAD_MANAGER_H
+#include <system_error>
#include <stdio.h>
#include <pthread.h>
#include <cds/threading/details/_common.h>
typedef int pthread_error_code;
/// pthread exception
- class pthread_exception: public cds::Exception {
- public:
- const pthread_error_code m_errCode ; ///< pthread error code, -1 if no pthread error code
+ class pthread_exception: public std::system_error
+ {
public:
/// Exception constructor
- pthread_exception( pthread_error_code nCode, const char * pszFunction )
- : m_errCode( nCode )
- {
- char buf[256];
- sprintf( buf, "Pthread error %i [function %s]", nCode, pszFunction );
- m_strMsg = buf;
- }
+ pthread_exception( int nCode, const char * pszFunction )
+ : std::system_error( nCode, std::system_category(), pszFunction )
+ {}
};
/// pthread TLS key holder
#ifndef __CDS_THREADING_DETAILS_WINTLS_MANAGER_H
#define __CDS_THREADING_DETAILS_WINTLS_MANAGER_H
+#include <system_error>
#include <stdio.h>
#include <cds/threading/details/_common.h>
typedef DWORD api_error_code;
/// TLS API exception
- class api_exception: public cds::Exception {
- public:
- const api_error_code m_errCode ; ///< error code
+ class api_exception : public std::system_error
+ {
public:
/// Exception constructor
api_exception( api_error_code nCode, const char * pszFunction )
- : m_errCode( nCode )
- {
- char buf[256];
-# if CDS_OS_TYPE == CDS_OS_MINGW
- sprintf( buf, "Win32 TLS API error %lu [function %s]", nCode, pszFunction );
-# else
- sprintf_s( buf, sizeof(buf)/sizeof(buf[0]), "Win32 TLS API error %lu [function %s]", nCode, pszFunction );
-# endif
- m_strMsg = buf;
- }
+ : std::system_error( static_cast<int>(nCode), std::system_category(), pszFunction )
+ {}
};
//@cond
This exception is raised when \p cds::opt::v::rcu_throw_deadlock deadlock checking policy
is used, see \p cds::opt::rcu_check_deadlock option.
*/
- class rcu_deadlock: public cds::Exception
+ class rcu_deadlock: public std::logic_error
{
//@cond
- typedef cds::Exception base_class;
public:
rcu_deadlock()
- : base_class( "RCU deadlock detected")
+ : std::logic_error( "RCU deadlock detected" )
{}
//@endcond
};
X(); \
} \
catch(...) { \
- Base::error("Test Failed: An Exception was thrown.", #X, __FILE__, __LINE__); \
+ Base::error("Test Failed: An exception was thrown.", #X, __FILE__, __LINE__); \
} \
} \
tearDown(); \