All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 <cstdint>
22 #include <iostream>
23 #include <memory>
24 #include <sstream>
25 #include <string>
26 
27 #include "sdf/system_util.hh"
28 
29 #ifdef _WIN32
30 // Disable warning C4251 which is triggered by
31 // std::unique_ptr
32 #pragma warning(push)
33 #pragma warning(disable: 4251)
34 #endif
35 
36 namespace sdf
37 {
40 
43  #define sdfthrow(msg) {std::ostringstream throwStream;\
44  throwStream << msg << std::endl << std::flush;\
45  throw sdf::Exception(__FILE__, __LINE__, throwStream.str()); }
46 
47  class ExceptionPrivate;
48 
52  {
54  public: Exception();
55 
60  public: Exception(const char *_file,
61  std::int64_t _line,
62  std::string _msg);
63 
66  public: Exception(const Exception &_e);
67 
69  public: virtual ~Exception();
70 
73  public: std::string GetErrorFile() const;
74 
77  public: std::string GetErrorStr() const;
78 
80  public: void Print() const;
81 
82 
86  public: friend std::ostream &operator<<(std::ostream& _out,
87  const sdf::Exception &_err)
88  {
89  return _out << _err.GetErrorStr();
90  }
91 
93  private: std::unique_ptr<ExceptionPrivate> dataPtr;
94  };
95 
101  {
103  public: InternalError();
104 
109  public: InternalError(const char *_file, std::int64_t _line,
110  const std::string _msg);
111 
113  public: virtual ~InternalError();
114  };
115 
122  {
130  public: AssertionInternalError(const char *_file,
131  std::int64_t _line,
132  const std::string _expr,
133  const std::string _function,
134  const std::string _msg = "");
136  public: virtual ~AssertionInternalError();
137  };
139 }
140 
141 #ifdef _WIN32
142 #pragma warning(pop)
143 #endif
144 
145 #endif
friend std::ostream & operator<<(std::ostream &_out, const sdf::Exception &_err)
stream insertion operator for Gazebo Error
Definition: Exception.hh:86
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition: Exception.hh:100
Class for generating exceptions.
Definition: Exception.hh:51
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48
std::string GetErrorStr() const
Return the error string.
Class for generating Exceptions which come from sdf assertions.
Definition: Exception.hh:121