DATAKIT API  V2025.1
util_exceptions_dtk.hpp
Go to the documentation of this file.
1 //Utility Exception Handle
2 #ifndef _UTIL_EXCEPTIONS_DTK_HPP
3 #define _UTIL_EXCEPTIONS_DTK_HPP
4 #define DtkTryCatch
5 
6 #include <assert.h>
7 
8 //exception generique
9 # define Dtk_ExceptionType "General Exception"
10 # define Dtk_OutOfRangeType "Out Of Range"
11 # define Dtk_NullPointerType "NULL Pointer"
12 # define Dtk_ErrorAllocationType "Can't Allocate Memory"
13 
14 //exemple de gestion d'exception
15 //Dtk_Try
16 //{
17 // bout de code critique
18 //}
19 //Dtk_Catch(Dtk_Exception& c , c.WriteMsg();Dtk_Throw(Dtk_ExceptionType);) //si on releve une Dtk_Exception => on peut la gerer
20 //Dtk_Catch(..., Dtk_Throw(Dtk_ExceptionType);) //pour tout autre exception => on lance une exception generale
21 
23 {
24  public:
25  Dtk_Exception( const char* inFileName, const int inLine, const char* inMsg )
26  {
27  _Msg = inMsg;
28  _File = inFileName;
29  _Line = inLine;
30  }
31  virtual ~Dtk_Exception() { ; }
32  virtual void WriteMsg()
33  {
34  // # ifdef WIN32
35  // char buffer[1024] = {0};
36  // sprintf( buffer, " File : %s[%u]", _File, _Line);
37  // MessageBoxA(NULL, buffer, _Msg, 16);
38  // # else
39  // fprintf(stderr, "%s\n File : %s[%u]", _Msg, _File, _Line);
40  // # endif
41  }
42  protected:
43  const char * _Msg;
44  const char * _File;
45  int _Line;
46  private:
47 
48 };
49 
50 #include <signal.h>
61 {
62 # ifndef _MSC_VER
63 #ifndef DTK_MINGW
64  private:
66  struct sigaction m_SignalHandler;
67 
69  struct sigaction m_Save_SIGINT_Handler;
70  struct sigaction m_Save_SIGTERM_Handler;
71  struct sigaction m_Save_SIGSEGV_Handler;
72  struct sigaction m_Save_SIGFPE_Handler;
73 #endif
74 # endif //#ifndef _MSC_VER
75 
78  static void SignalHandler( const int inSignal );
79  public:
85 };
86 # ifdef DtkTryCatch
87 # define Dtk_Try try
88 # define Dtk_Catch(inExceptionType, inAction) catch( inExceptionType ){ inAction }
89 # else
90 # define Dtk_Try
91 # define Dtk_Catch(inExceptionType, inAction)
92 # endif
93 # define Dtk_Throw(inExceptionType) throw(Dtk_Exception(__FILE__, __LINE__, inExceptionType))
94 # define Dtk_ReThrow() throw
95 
96 
97 
98 
99 #endif
Dtk_Exception::_File
const char * _File
Definition: util_exceptions_dtk.hpp:44
Dtk_LinuxSignalHandler::RestoreSignalHandler
void RestoreSignalHandler()
This method restores the classic signal handler.
Dtk_LinuxSignalHandler::Dtk_LinuxSignalHandler
Dtk_LinuxSignalHandler()
Dtk_Exception::Dtk_Exception
Dtk_Exception(const char *inFileName, const int inLine, const char *inMsg)
Definition: util_exceptions_dtk.hpp:25
Dtk_LinuxSignalHandler::BypassSignalHandler
void BypassSignalHandler()
this method bypasses the classic signal handler.
Dtk_Exception::_Line
int _Line
Definition: util_exceptions_dtk.hpp:45
Dtk_LinuxSignalHandler
This class lets you handle POSIX signals. And these systems, memory corruption doesn't throw an excep...
Definition: util_exceptions_dtk.hpp:61
Dtk_Exception
Definition: util_exceptions_dtk.hpp:23
Dtk_Exception::~Dtk_Exception
virtual ~Dtk_Exception()
Definition: util_exceptions_dtk.hpp:31
Dtk_Exception::_Msg
const char * _Msg
Definition: util_exceptions_dtk.hpp:43
Dtk_Exception::WriteMsg
virtual void WriteMsg()
Definition: util_exceptions_dtk.hpp:32