libSBNW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Modules Pages
SagittariusException.hpp
1 /*== SAGITTARIUS =====================================================================
2  * Copyright (c) 2012, Jesse K Medley
3  * All rights reserved.
4 
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of The University of Washington nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 //== BEGINNING OF CODE ===============================================================
29 
30 #ifndef _SAGITTARIUS_EXCEPTION_H_
31 #define _SAGITTARIUS_EXCEPTION_H_
32 
33 //== INCLUDES ========================================================================
34 
36 #include "graphfab/core/SagittariusException.hpp"
37 #include "graphfab/util/string.h"
38 #include <exception>
39 
40 namespace Graphfab
41 {
42 
43  //== CLASSES =====================================================================
44 
45  //########################################################
46  //CLASS Exception
47  // Used in place of std::exception within Sagittarius
48  // Provides more detailed exception information
49  // (such as file and line number)
50  // Inspired by Ogre exceptions
51  //########################################################
52  class _GraphfabExport Exception : public std::exception
53  {
54  public:
55  enum ExceptionTypeSet
56  {
57  EXC_UNKNOWN,
58  EXC_FREAD_FAIL,
59  EXC_FWRITE_FAIL,
60  EXC_ACCESS_VIOLATION,
61  EXC_SANITY_CHECK,
62  EXC_REDUNDANCY_CHECK_FAILURE,
63  EXC_IMPOSSIBLE_CMD,
64  EXC_INVALID_PARAMETER,
65  EXC_INTERNAL_CHECK_FAILURE
66  };
67 
68  Exception( const int type, const String& desc, const String& origin, const char* name, const char* file, const long line);
69 
70  ~Exception() throw() {}
71 
72  void operator = ( const Exception &rval );
73 
74  virtual String getReport() const;
75 
76  //Can't have a const int return type or warnings about ignored qualifiers. Stupid compiler.
77  //Idea: maybe it really SHOULD be const int. Think about it.
78  virtual int getType() const throw();
79 
80  virtual const String& getDescription() const { return m_desc; }
81 
82  virtual const String& getOrigin() const { return m_origin; }
83 
84  virtual const String& getFile() const { return m_file; }
85 
86  virtual long getLine() const { return m_line; }
87 
88  //Override std::exception::what
89  const char* what() const throw() {
90  // leak
91  return gf_strclone(getReport().c_str());
92  }
93 
94  protected:
95  int m_type;
96  String m_desc;
97  String m_origin;
98  String m_name;
99  String m_file;
100  long m_line;
101 
102  };
103 
104  template <int t>
106  {
107  enum { type = t };
108  };
109 
110  //Exception classes
111 
117  class _GraphfabExport UnknownException : public Exception
118  {
119  public:
120  UnknownException( const String& desc, const String& origin, const char* file, const long line )
121  : Exception( Exception::EXC_UNKNOWN, desc, origin, "UnknownException", file, line) {}
122  };
123 
128  {
129  public:
130  FileReadFailureException( const String& desc, const String& origin, const char* file, const long line )
131  : Exception( Exception::EXC_FREAD_FAIL, desc, origin, "FileReadFailureException", file, line) {}
132  };
133 
137  class _GraphfabExport FileWriteFailureException : public Exception
138  {
139  public:
140  FileWriteFailureException( const String& desc, const String& origin, const char* file, const long line )
141  : Exception( Exception::EXC_FWRITE_FAIL, desc, origin, "FileWriteFailureException", file, line) {}
142  };
143 
148  class _GraphfabExport AccessViolationException : public Exception
149  {
150  public:
151  AccessViolationException( const String& desc, const String& origin, const char* file, const long line )
152  : Exception( Exception::EXC_ACCESS_VIOLATION, desc, origin, "AccessViolationException", file, line) {}
153  };
154 
158  class _GraphfabExport SanityCheckException : public Exception
159  {
160  public:
161  SanityCheckException( const String& desc, const String& origin, const char* file, const long line )
162  : Exception( Exception::EXC_SANITY_CHECK, desc, origin, "SanityCheckException", file, line) {}
163  };
164 
171  class _GraphfabExport RedundancyCheckFailureException : public Exception
172  {
173  public:
174  RedundancyCheckFailureException( const String& desc, const String& origin, const char* file, const long line )
175  : Exception( Exception::EXC_REDUNDANCY_CHECK_FAILURE, desc, origin, "RedundancyCheckFailureException", file, line) {}
176  };
177 
181  class _GraphfabExport ImpossibleCommandException : public Exception
182  {
183  public:
184  ImpossibleCommandException( const String& desc, const String& origin, const char* file, const long line )
185  : Exception( Exception::EXC_IMPOSSIBLE_CMD, desc, origin, "ImpossibleCommandException", file, line) {}
186  };
187 
191  class _GraphfabExport InvalidParameterException : public Exception
192  {
193  public:
194  InvalidParameterException( const String& desc, const String& origin, const char* file, const long line )
195  : Exception( Exception::EXC_INVALID_PARAMETER, desc, origin, "InvalidParameterException", file, line) {}
196  };
197 
203  class _GraphfabExport InternalCheckFailureException : public Exception
204  {
205  public:
206  InternalCheckFailureException( const String& desc, const String& origin, const char* file, const long line )
207  : Exception( Exception::EXC_INTERNAL_CHECK_FAILURE, desc, origin, "InternalCheckFailureException", file, line) {}
208  };
209 
214  {
215  public:
216  RuntimeException( const String& desc, const String& origin, const char* file, const long line )
217  : Exception( Exception::EXC_SANITY_CHECK, desc, origin, "RuntimeException", file, line) {}
218  };
219 
221  {
222  public:
223  MissingDataException( const String& desc, const String& origin, const char* file, const long line )
224  : Exception( Exception::EXC_SANITY_CHECK, desc, origin, "MissingDataException", file, line) {}
225  };
226 
228  {
229  public:
230  UnexpectedDataException( const String& desc, const String& origin, const char* file, const long line )
231  : Exception( Exception::EXC_SANITY_CHECK, desc, origin, "UnexpectedDataException", file, line) {}
232  };
233 
235  {
236  public:
237  BoundsCheckFailure( const String& desc, const String& origin, const char* file, const long line )
238  : Exception( Exception::EXC_SANITY_CHECK, desc, origin, "BoundsCheckFailure", file, line) {}
239  };
240 
241  //########################################################
242  //CLASS ExceptionFactory
243  // Generates specific exceptions (i.e. derived classes of
244  // Exception) based on the type argument
245  // One of the few cases in which the factory can return
246  // by value
247  //########################################################
249  {
250  public:
252  const String& desc, const String& origin,
253  const char* file, const long line) {
254  return UnknownException(desc, origin, file, line);
255  }
257  const String& desc, const String& origin,
258  const char* file, const long line) {
259  return FileReadFailureException(desc, origin, file, line);
260  }
262  const String& desc, const String& origin,
263  const char* file, const long line) {
264  return FileWriteFailureException(desc, origin, file, line);
265  }
267  const String& desc, const String& origin,
268  const char* file, const long line) {
269  return AccessViolationException(desc, origin, file, line);
270  }
272  const String& desc, const String& origin,
273  const char* file, const long line) {
274  return SanityCheckException(desc, origin, file, line);
275  }
277  const String& desc, const String& origin,
278  const char* file, const long line) {
279  return RedundancyCheckFailureException(desc, origin, file, line);
280  }
282  const String& desc, const String& origin,
283  const char* file, const long line) {
284  return ImpossibleCommandException(desc, origin, file, line);
285  }
287  const String& desc, const String& origin,
288  const char* file, const long line) {
289  return InvalidParameterException(desc, origin, file, line);
290  }
292  const String& desc, const String& origin,
293  const char* file, const long line) {
294  return InternalCheckFailureException(desc, origin, file, line);
295  }
296  };
297 
298 #define SBNW_THROW( type, desc, origin ) throw type( desc, origin, __FILE__, __LINE__ );
299 } //namespace Sagittarius
300 
301 #endif
Definition: SagittariusException.hpp:105
Definition: SagittariusException.hpp:220
Common required definitions.
C string utilities.
Definition: SagittariusException.hpp:52
Definition: SagittariusException.hpp:234
Definition: SagittariusException.hpp:213
Definition: SagittariusException.hpp:181
Definition: SagittariusCommon.cpp:38
Definition: SagittariusException.hpp:137
Definition: SagittariusException.hpp:127
Definition: SagittariusException.hpp:227
Definition: SagittariusException.hpp:171
Definition: SagittariusException.hpp:148
Definition: SagittariusException.hpp:158
Definition: SagittariusException.hpp:117
Definition: SagittariusException.hpp:191
Definition: SagittariusException.hpp:248
Definition: SagittariusException.hpp:203