SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Exception.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2012 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27  */
28 /// @todo Documentation Core/Utils/Exception.h
29 
30 #ifndef CORE_UTILS_EXCEPTION_H
31 #define CORE_UTILS_EXCEPTION_H
32 
33 #include <stdexcept>
34 #include <boost/exception/all.hpp>
35 #include <boost/tuple/tuple.hpp>
36 #include <boost/numeric/interval.hpp>
37 #include <Core/Utils/share.h>
38 
39 namespace SCIRun
40 {
41 namespace Core
42 {
43  //See:
44  //http://www.boost.org/doc/libs/1_51_0/libs/exception/doc/exception_types_as_simple_semantic_tags.html
45 
46  struct SCISHARE ExceptionBase : virtual std::exception, virtual boost::exception
47  {
48  virtual const char* what() const throw();
49  std::string typeName() const;
50  };
51 
52  typedef boost::error_info<struct tag_error_message, std::string> ErrorMessage;
53  typedef boost::error_info<struct tag_null_object, std::string> NullObjectInfo;
54  typedef boost::error_info<struct tag_file_not_found, std::string> FileNotFound;
55  /// @todo discuss location/type
56  typedef boost::error_info<struct tag_linear_algebra_error, std::string> LinearAlgebraErrorMessage;
57  /// @todo make macro for various types
58  typedef boost::error_info<struct tag_double_out_of_range, boost::tuple<std::string, double, boost::numeric::interval<double> > > DoubleOutOfRangeInfo;
59  typedef boost::error_info<struct tag_int_out_of_range, boost::tuple<std::string, int, boost::numeric::interval<int> > > IntOutOfRangeInfo;
60 
62 
63  #define ENSURE_NOT_NULL(var, message) if (!(var)) BOOST_THROW_EXCEPTION(SCIRun::Core::NullPointerException() << SCIRun::Core::NullObjectInfo(message))
64 
66 
67  #define THROW_OUT_OF_RANGE(message) BOOST_THROW_EXCEPTION(SCIRun::Core::OutOfRangeException() << SCIRun::Core::ErrorMessage(message))
68 
70 
71  #define THROW_INVALID_ARGUMENT(message) BOOST_THROW_EXCEPTION(SCIRun::Core::InvalidArgumentException() << SCIRun::Core::ErrorMessage(message))
72 
73  typedef boost::error_info<struct tag_dimension_mismatch, std::string> DimensionMismatchInfo;
74  typedef boost::error_info<struct tag_invalid_argument_value, std::string> InvalidArgumentValueInfo;
75  typedef boost::error_info<struct tag_not_implemented, std::string> NotImplementedInfo;
76 
77  /// @todo move these exceptions to new exception header file once it exists
79  {
80  };
81 
83  {
84  };
85 
86  /// @todo should not need this in production code.
87  //
88  // Any prototype code using this exception should be reviewed and improved!!!
90  {
91  };
92 
93 #define ENSURE_DIMENSIONS_MATCH(var1, var2, message) if (var1 != var2) \
94  BOOST_THROW_EXCEPTION(SCIRun::Core::DimensionMismatch() << SCIRun::Core::DimensionMismatchInfo( \
95  SCIRun::Core::DimensionMismatchInfo::value_type( \
96  std::string(message) )))
97 
98 #define REPORT_INVALID_ARGUMENT_VALUE(message) \
99  BOOST_THROW_EXCEPTION(SCIRun::Core::InvalidArgumentValue() << SCIRun::Core::InvalidArgumentValueInfo( \
100  SCIRun::Core::InvalidArgumentValueInfo::value_type( \
101  std::string(message) )))
102 
103 /// @todo should not need this in production code.
104 //
105 // Any prototype code using this exception should be reviewed and improved!!!
106 #define REPORT_NOT_IMPLEMENTED(message) \
107  BOOST_THROW_EXCEPTION(SCIRun::Core::NotImplemented() << SCIRun::Core::NotImplementedInfo( \
108  SCIRun::Core::NotImplementedInfo::value_type( \
109  std::string(message) )))
110 
112 
113 #define ASSERTMSG(condition,message) \
114  if(!(condition)){ \
115  BOOST_THROW_EXCEPTION(SCIRun::Core::AssertionFailed() << SCIRun::Core::ErrorMessage(message)); \
116  }
117 
118 }
119 }
120 
121 #endif
Definition: Exception.h:69
Definition: Exception.h:111
boost::error_info< struct tag_invalid_argument_value, std::string > InvalidArgumentValueInfo
Definition: Exception.h:74
Definition: Exception.h:61
boost::error_info< struct tag_linear_algebra_error, std::string > LinearAlgebraErrorMessage
Definition: Exception.h:56
#define SCISHARE
Definition: share.h:39
boost::error_info< struct tag_int_out_of_range, boost::tuple< std::string, int, boost::numeric::interval< int > > > IntOutOfRangeInfo
Definition: Exception.h:59
boost::error_info< struct tag_error_message, std::string > ErrorMessage
Definition: Exception.h:52
Definition: Exception.h:46
boost::error_info< struct tag_double_out_of_range, boost::tuple< std::string, double, boost::numeric::interval< double > > > DoubleOutOfRangeInfo
Definition: Exception.h:58
Definition: Exception.h:82
Definition: Exception.h:89
Definition: Exception.h:78
boost::error_info< struct tag_null_object, std::string > NullObjectInfo
Definition: Exception.h:53
Definition: Exception.h:65
boost::error_info< struct tag_dimension_mismatch, std::string > DimensionMismatchInfo
Definition: Exception.h:73
boost::error_info< struct tag_file_not_found, std::string > FileNotFound
Definition: Exception.h:54
boost::error_info< struct tag_not_implemented, std::string > NotImplementedInfo
Definition: Exception.h:75