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 <gz/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  GZ_UTILS_IMPL_PTR(dataPtr)
105  };
106 
112  {
114  public: InternalError();
115 
120  public: InternalError(const char *_file, std::int64_t _line,
121  // cppcheck-suppress passedByValue
122  const std::string _msg);
123 
125  public: virtual ~InternalError();
126  };
127 
134  {
142  public: AssertionInternalError(const char *_file,
143  std::int64_t _line,
144  // cppcheck-suppress passedByValue
145  const std::string _expr,
146  // cppcheck-suppress passedByValue
147  const std::string _function,
148  // cppcheck-suppress passedByValue
149  const std::string _msg = "");
151  public: virtual ~AssertionInternalError();
152  };
154  }
155 }
156 
157 #endif
Class for generating Exceptions which come from sdf assertions.
Definition: Exception.hh:134
AssertionInternalError(const char *_file, std::int64_t _line, const std::string _expr, const std::string _function, const std::string _msg="")
Constructor for assertions.
Class for generating exceptions.
Definition: Exception.hh:49
virtual ~Exception()=default
Destructor.
Exception(Exception &&_e) noexcept=default
Move constructor.
std::string GetErrorStr() const
Return the error string.
void Print() const
Print the exception to std out.
Exception & operator=(Exception &&_exception) noexcept=default
Move assignment operator.
friend std::ostream & operator<<(std::ostream &_out, const sdf::Exception &_err)
stream insertion operator for Gazebo Error
Definition: Exception.hh:97
Exception(const Exception &_e)=default
Copy constructor.
std::string GetErrorFile() const
Return the error function.
Exception(const char *_file, std::int64_t _line, std::string _msg)
Default constructor.
Exception & operator=(const Exception &_exception)=default
Assignment operator.
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition: Exception.hh:112
InternalError(const char *_file, std::int64_t _line, const std::string _msg)
Default constructor.
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25