FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
TCLException.h
Go to the documentation of this file.
1 /*
2  This software is Copyright by the Board of Trustees of Michigan
3  State University (c) Copyright 2017.
4 
5  You may use this software under the terms of the GNU public license
6  (GPL). The terms of this license are described at:
7 
8  http://www.gnu.org/licenses/gpl.txt
9 
10  Authors:
11  Ron Fox
12  Giordano Cerriza
13  NSCL
14  Michigan State University
15  East Lansing, MI 48824-1321
16 */
17 
21 // CTCLException.h:
22 //
23 // This file defines the CTCLException class.
24 //
25 // Author:
26 // Ron Fox
27 // NSCL
28 // Michigan State University
29 // East Lansing, MI 48824-1321
30 // mailto:fox@nscl.msu.edu
31 //
32 // Copyright 1999 NSCL, All Rights Reserved.
33 //
35 
36 #ifndef CTCLEXCEPTION_H //Required for current class
37 #define CTCLEXCEPTION_H
38 
39 
40 #include <tcl.h>
41 
42 #ifndef TCLINTERPRETEROBJECT_H
43 #include "TCLInterpreterObject.h"
44 #endif
45 
46 #ifndef TCLINTERPRETER_H
47 #include "TCLInterpreter.h"
48 #endif
49 
50 #ifndef TCLRESULT_H
51 #include "TCLResult.h"
52 #endif
53 
54  //Required for base classes
55 #ifndef EXCEPTION_H
56 #include "Exception.h"
57 #endif
58 
59 #include <string>
60 #ifndef TCLPLUSTYPES_H
61 #include <libtclplusdatatypes.h>
62 #endif
63 
64 
66 {
67  TCLPLUS::Int_t m_nReason; // Reason the exception was thrown
68  // TCL_ERROR - Error in script.
69  // TCL_BREAK - Break from loop.
70  // TCL_CONTINUE - continue loop.
71  // TCL_RETURN - fuction return.
72  // NOTE: Really no business throwing anything
73  // but TCL_ERRORs.
74  std::string m_ResultText; // Cached result text at construction time.
75 public:
76  //Default constructor
77 
78  CTCLException (CTCLInterpreter& am_rInterpreter,
79  TCLPLUS::Int_t am_nReason,
80  const char* pString) :
81  CTCLInterpreterObject(&am_rInterpreter),
82  CException(pString),
83  m_nReason(am_nReason)
84  {
85  m_ResultText = std::string(Tcl_GetStringResult(am_rInterpreter.getInterpreter()));
86  }
87  CTCLException(CTCLInterpreter& am_rInterpreter,
88  TCLPLUS::Int_t am_nReason,
89  const std::string& rString) :
90  CTCLInterpreterObject(&am_rInterpreter),
91  CException(rString),
92  m_nReason(am_nReason)
93  {
94  m_ResultText = std::string(Tcl_GetStringResult(am_rInterpreter.getInterpreter()));
95  }
96  virtual ~CTCLException ( ) { } //Destructor
97 
98  //Copy constructor
99 
100  CTCLException (const CTCLException& aCTCLException ) :
101  CTCLInterpreterObject (aCTCLException),
102  CException (aCTCLException)
103  {
104  m_nReason = aCTCLException.m_nReason;
105  m_ResultText = aCTCLException.m_ResultText;
106  }
107 
108  //Operator= Assignment Operator
109 
110  CTCLException operator= (const CTCLException& aCTCLException)
111  {
112  if (this == &aCTCLException) return *this;
113  CTCLInterpreterObject::operator= (aCTCLException);
114  CException::operator= (aCTCLException);
115 
116  if(this != &aCTCLException) {
117  m_nReason = aCTCLException.m_nReason;
118  m_ResultText = aCTCLException.m_ResultText;
119  }
120  return *this;
121  }
122 
123  //Operator== Equality Operator
124 
125  int operator== (const CTCLException& aCTCLException)
126  { return (
127  (CTCLInterpreterObject::operator== (aCTCLException)) &&
128  (CException::operator== (aCTCLException)) &&
129  (m_nReason == aCTCLException.m_nReason)
130  );
131  }
132  // Selectors: - Stick to generic CException and CTCLInterpreterObject
133  // interfaces unless you really know what you're doing.
134  //
135 public:
136 
137  TCLPLUS::Int_t getReason() const
138  {
139  return m_nReason;
140  }
141  std::string getTraceback();
142  static std::string getTraceback(CTCLInterpreter& interp);
143  //
144  // Mutators: Available to derivce classes only:
145  //
146 protected:
147 
148 
149  void setInterpreter (CTCLInterpreter& am_rInterpreter)
150  {
151  Bind(am_rInterpreter);
152  }
153  void setReason (TCLPLUS::Int_t am_nReason)
154  {
155  m_nReason = am_nReason;
156  }
157  // TCL Specific interface:
158  //
159 public:
160  void AddErrorInfo (const char* pMessage) ;
161  void AddErrorInfo(const std::string& rMessage) {
162  AddErrorInfo(rMessage.c_str());
163  }
164  void AddErrorInfo(const CTCLString& rMessage) {
165  AddErrorInfo((const char*)(rMessage));
166  }
167 
168  void SetErrorCode (const char* pMessage,
169  const char* pMnemonic="???",
170  const char* pFacility="TCL",
171  const char* pSeverity="FATAL") ;
172  void SetErrorCode(const std::string rMessage,
173  const std::string &rMnemonic=std::string("???"),
174  const std::string &rFacility=std::string("TCL"),
175  const std::string &rSeverity=std::string("FATAL")) {
176  SetErrorCode(rMessage.c_str(), rMnemonic.c_str(),
177  rFacility.c_str(), rSeverity.c_str());
178  }
179 
180  //
181  // CException generic interface:
182  //
183  virtual const char* ReasonText () const;
184  virtual TCLPLUS::Int_t ReasonCode () const ;
185 private:
186  CTCLResult GetResult ();
187 
188 };
189 
190 #endif
Definition: TCLException.h:65
std::string getTraceback()
Definition: TCLException.cpp:166
Definition: TCLString.h:28
Definition: TCLInterpreterObject.h:46
Definition: TCLInterpreter.h:59
Definition: TCLResult.h:55
Definition: Exception.h:41