All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
Exception.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _SDF_EXCEPTION_HH_
19 #define _SDF_EXCEPTION_HH_
20 
21 #include <iostream>
22 #include <sstream>
23 #include <string>
24 
25 namespace sdf
26 {
29 
32  #define sdfthrow(msg) {std::ostringstream throwStream;\
33  throwStream << msg << std::endl << std::flush;\
34  throw sdf::Exception(__FILE__, __LINE__, throwStream.str()); }
35 
38  class Exception
39  {
41  public: Exception();
42 
47  public: Exception(const char *_file,
48  int _line,
49  std::string _msg);
50 
52  public: virtual ~Exception();
53 
56  public: std::string GetErrorFile() const;
57 
60  public: std::string GetErrorStr() const;
61 
63  public: void Print() const;
64 
66  private: std::string file;
67 
69  private: int line;
70 
72  private: std::string str;
73 
77  public: friend std::ostream &operator<<(std::ostream& _out,
78  const sdf::Exception &_err)
79  {
80  return _out << _err.GetErrorStr();
81  }
82  };
83 
88  class InternalError : public Exception
89  {
91  public: InternalError();
92 
97  public: InternalError(const char *_file, int _line,
98  const std::string _msg);
99 
101  public: virtual ~InternalError();
102  };
103 
110  {
118  public: AssertionInternalError(const char *_file,
119  int _line,
120  const std::string _expr,
121  const std::string _function,
122  const std::string _msg = "");
124  public: virtual ~AssertionInternalError();
125  };
127 }
128 
129 #endif
virtual ~InternalError()
Destructor.
friend std::ostream & operator<<(std::ostream &_out, const sdf::Exception &_err)
stream insertion operator for Gazebo Error
Definition: Exception.hh:77
virtual ~AssertionInternalError()
Destructor.
InternalError()
Constructor.
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition: Exception.hh:88
Class for generating exceptions.
Definition: Exception.hh:38
std::string GetErrorFile() const
Return the error function.
virtual ~Exception()
Destructor.
Exception()
Constructor.
std::string GetErrorStr() const
Return the error string.
Class for generating Exceptions which come from sdf assertions.
Definition: Exception.hh:109
void Print() const
Print the exception to std out.
AssertionInternalError(const char *_file, int _line, const std::string _expr, const std::string _function, const std::string _msg="")
Constructor for assertions.