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  // cppcheck-suppress passedByValue
130  const std::string _msg);
131 
133  public: virtual ~InternalError();
134  };
135 
142  {
150  public: AssertionInternalError(const char *_file,
151  std::int64_t _line,
152  // cppcheck-suppress passedByValue
153  const std::string _expr,
154  // cppcheck-suppress passedByValue
155  const std::string _function,
156  // cppcheck-suppress passedByValue
157  const std::string _msg = "");
159  public: virtual ~AssertionInternalError();
160  };
162  }
163 }
164 
165 #ifdef _WIN32
166 #pragma warning(pop)
167 #endif
168 
169 #endif
sdf::v9::Exception
Class for generating exceptions.
Definition: Exception.hh:56
sdf
namespace for Simulation Description Format parser
Definition: Actor.hh:32
sdf::v9::InternalError
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition: Exception.hh:119
sdf::v9::Exception::GetErrorStr
std::string GetErrorStr() const
Return the error string.
SDFORMAT_VISIBLE
#define SDFORMAT_VISIBLE
Definition: system_util.hh:48
sdf::v9::AssertionInternalError
Class for generating Exceptions which come from sdf assertions. They include information about the as...
Definition: Exception.hh:141
system_util.hh
sdf::v9::Exception::operator<<
friend std::ostream & operator<<(std::ostream &_out, const sdf::Exception &_err)
stream insertion operator for Gazebo Error
Definition: Exception.hh:105