File: exceptions.hh

package info (click to toggle)
tigr-glimmer 3.02b-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 13,948 kB
  • sloc: cpp: 24,416; awk: 232; csh: 220; makefile: 147; sh: 51
file content (121 lines) | stat: -rw-r--r-- 2,967 bytes parent folder | download | duplicates (12)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//  A. L. Delcher
//
//  File:  exceptions.hh
//
//  Last Modified:  13 June 2005
//
//  Include file for exception types



#ifndef  __EXCEPTIONS_HH_INCLUDED
#define  __EXCEPTIONS_HH_INCLUDED


// Stolen from AMOS exceptions code



const std :: string  NULL_STRING = "";  //!< null string



//================================================ Exception_t =================
//! \brief The base exception class
//!
//! All other exceptions will be derived from this class, so catching for
//! this class should effectively catch all exceptions.
//!
//==============================================================================

class Exception_t  :  public std :: exception
{

private:

  std :: string  what_m;    //!< description of exception
  int  line_m;              //!< line number of exception
  std ::  string file_m;    //!< file name of exception


public:

  //---------------------------------------------- Exception_t -----------------
  //! \brief Informative constructor
  //!
  //! \param what Brief description of the exception
  //! \param line Line number of the exception
  //! \param file File name of the exception
  //!
  Exception_t (const std :: string & what,
	       int line = 0,
	       const std :: string & file = NULL_STRING)
    : what_m (what), line_m (line), file_m (file)
  { }


  //---------------------------------------------- ~Exception_t ----------------
  //! \brief Default destructor
  //!
  ~Exception_t ( ) throw()
  { }


  //---------------------------------------------- file ------------------------
  //! \brief Returns the file (if available) of the exception
  //!
  virtual const char * file ( ) const
  {
    return file_m . c_str( );
  }


  //---------------------------------------------- line ------------------------
  //! \brief Returns the line number (if available) of the exception
  //!
  virtual int line ( ) const
  {
    return line_m;
  }


  //---------------------------------------------- what ------------------------
  //! \brief Returns a short description (if available) of the exception
  //!
  virtual const char * what ( ) const throw( )
  {
    return what_m . c_str( );
  }

};



//----------------------------------------------------- operator<< -------------
//! \brief Dump Exception_t info to an ostream
//!
inline std :: ostream & operator<< (std :: ostream & out, const Exception_t & e)
{
  out << "WHAT: " << e . what( ) << std::endl;
  out << "LINE: " << e . line( ) << std::endl;
  out << "FILE: " << e . file( ) << std::endl;
  return out;
}


//----------------------------------------------------- operator<< -------------
//! \brief Dump exception info to an ostream
//!
inline std::ostream & operator<< (std::ostream & out, const std::exception & e)
{
  out << "WHAT: " << e . what( ) << std::endl;
  return out;
}



//-- Helpful exception throw macros
#define SIMPLE_THROW(A) throw Exception_t (A, __LINE__, __FILE__)


#endif // #ifndef __EXCEPTIONS_HH_INCLUDED