File: error.h

package info (click to toggle)
bagel 1.2.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 134,940 kB
  • sloc: cpp: 1,236,571; javascript: 15,383; python: 1,461; ansic: 674; makefile: 253; sh: 109
file content (46 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef __BTAS_ERROR_H
#define __BTAS_ERROR_H

#include <exception>

namespace btas {

  /// exception class, used to mark exceptions specific to BTAS
  class exception : public std::exception {
    public:
      exception(const char* m) : message_(m) { }

      virtual const char* what() const noexcept { return message_; }

    private:
      const char* message_;
  }; // class exception

  /// Place a break point in this function to stop before btas::exception is thrown.
  inline void exception_break() { }

} // namespace btas

// configure BTAS_ASSERT
#ifdef BTAS_ASSERT_THROWS

#define BTAS_STRINGIZE( s ) #s

#define BTAS_EXCEPTION_MESSAGE( file , line , mess ) \
  "BTAS: exception at " file "(" BTAS_STRINGIZE( line ) "): " mess ". Break in btas::exception_break to learn more."

#define BTAS_EXCEPTION( m ) \
    { \
      btas::exception_break(); \
      throw btas::exception ( BTAS_EXCEPTION_MESSAGE( __FILE__ , __LINE__ , m ) ); \
    }

#define BTAS_ASSERT( a )  if(! ( a ) ) BTAS_EXCEPTION( "assertion failed" )

#else // defined BTAS_ASSERT_THROWS

#define BTAS_ASSERT( a )  assert((a));

#endif // defined BTAS_ASSERT_THROWS

#endif // __BTAS_ERROR_H