Loading...
Searching...
No Matches
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
37namespace 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
Class for generating Exceptions which come from sdf assertions.
Definition Exception.hh:142
virtual ~AssertionInternalError()
Destructor.
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:57
Exception()
Constructor.
Exception(const Exception &_e)
Copy constructor.
std::string GetErrorStr() const
Return the error string.
Exception(const char *_file, std::int64_t _line, std::string _msg)
Default constructor.
friend std::ostream & operator<<(std::ostream &_out, const sdf::Exception &_err)
stream insertion operator for Gazebo Error
Definition Exception.hh:105
virtual ~Exception()
Destructor.
void Print() const
Print the exception to std out.
Exception & operator=(const Exception &_exception)
Assignment operator.
Exception & operator=(Exception &&_exception)
Move assignment operator.
Exception(Exception &&_e) noexcept
Move constructor.
std::string GetErrorFile() const
Return the error function.
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition Exception.hh:120
InternalError(const char *_file, std::int64_t _line, const std::string _msg)
Default constructor.
InternalError()
Constructor.
virtual ~InternalError()
Destructor.
namespace for Simulation Description Format parser
Definition Actor.hh:33
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition system_util.hh:48