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 <ignition/utils/ImplPtr.hh>
28 #include <sdf/sdf_config.h>
29 #include "sdf/system_util.hh"
30 
31 namespace sdf
32 {
33  // Inline bracket to help doxygen filtering.
34  inline namespace SDF_VERSION_NAMESPACE {
35  //
36 
39 
42  #define sdfthrow(msg) {std::ostringstream throwStream;\
43  throwStream << msg << std::endl << std::flush;\
44  throw sdf::Exception(__FILE__, __LINE__, throwStream.str()); }
45 
49  {
51  public: Exception();
52 
57  public: Exception(const char *_file,
58  std::int64_t _line,
59  std::string _msg);
60 
63  public: Exception(const Exception &_e) = default;
64 
67  public: Exception(Exception &&_e) noexcept = default;
68 
72  public: Exception &operator=(const Exception &_exception) = default;
73 
77  public: Exception &operator=(Exception &&_exception) noexcept = default;
78 
80  public: virtual ~Exception() = default;
81 
84  public: std::string GetErrorFile() const;
85 
88  public: std::string GetErrorStr() const;
89 
91  public: void Print() const;
92 
93 
97  public: friend std::ostream &operator<<(std::ostream& _out,
98  const sdf::Exception &_err)
99  {
100  return _out << _err.GetErrorStr();
101  }
102 
104  IGN_UTILS_IMPL_PTR(dataPtr)
105  };
106 
112  {
114  public: InternalError();
115 
120  public: InternalError(const char *_file, std::int64_t _line,
121  const std::string _msg);
122 
124  public: virtual ~InternalError();
125  };
126 
133  {
141  public: AssertionInternalError(const char *_file,
142  std::int64_t _line,
143  const std::string _expr,
144  const std::string _function,
145  const std::string _msg = "");
147  public: virtual ~AssertionInternalError();
148  };
150  }
151 }
152 
153 #endif
Class for generating Exceptions which come from sdf assertions.
Definition: Exception.hh:132
friend std::ostream & operator<<(std::ostream &_out, const sdf::Exception &_err)
stream insertion operator for Gazebo Error
Definition: Exception.hh:97
Class for generating exceptions.
Definition: Exception.hh:48
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:41
namespace for Simulation Description Format parser
Definition: Actor.hh:33
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition: Exception.hh:111