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/sdf_config.h>
28 #include "sdf/system_util.hh"
29 
30 #ifdef _WIN32
31 // Disable warning C4251 which is triggered by
32 // std::unique_ptr
33 #pragma warning(push)
34 #pragma warning(disable: 4251)
35 #endif
36 
37 namespace sdf
38 {
39  // Inline bracket to help doxygen filtering.
40  inline namespace SDF_VERSION_NAMESPACE {
41  //
42 
45 
48  #define sdfthrow(msg) {std::ostringstream throwStream;\
49  throwStream << msg << std::endl << std::flush;\
50  throw sdf::Exception(__FILE__, __LINE__, throwStream.str()); }
51 
52  class ExceptionPrivate;
53 
57  {
59  public: Exception();
60 
65  public: Exception(const char *_file,
66  std::int64_t _line,
67  std::string _msg);
68 
71  public: Exception(const Exception &_e);
72 
75  public: Exception(Exception &&_e) noexcept;
76 
80  public: Exception &operator=(const Exception &_exception);
81 
85  public: Exception &operator=(Exception &&_exception);
86 
88  public: virtual ~Exception();
89 
92  public: std::string GetErrorFile() const;
93 
96  public: std::string GetErrorStr() const;
97 
99  public: void Print() const;
100 
101 
105  public: friend std::ostream &operator<<(std::ostream& _out,
106  const sdf::Exception &_err)
107  {
108  return _out << _err.GetErrorStr();
109  }
110 
112  private: std::unique_ptr<ExceptionPrivate> dataPtr;
113  };
114 
120  {
122  public: InternalError();
123 
128  public: InternalError(const char *_file, std::int64_t _line,
129  const std::string _msg);
130 
132  public: virtual ~InternalError();
133  };
134 
141  {
149  public: AssertionInternalError(const char *_file,
150  std::int64_t _line,
151  const std::string _expr,
152  const std::string _function,
153  const std::string _msg = "");
155  public: virtual ~AssertionInternalError();
156  };
158  }
159 }
160 
161 #ifdef _WIN32
162 #pragma warning(pop)
163 #endif
164 
165 #endif
Class for generating exceptions.
Definition: Exception.hh:56
Class for generating Exceptions which come from sdf assertions.
Definition: Exception.hh:140
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48
friend std::ostream & operator<<(std::ostream &_out, const sdf::Exception &_err)
stream insertion operator for Gazebo Error
Definition: Exception.hh:105
namespace for Simulation Description Format parser
Definition: Actor.hh:32
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition: Exception.hh:119