1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* Copyright 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef SDF_EXCEPTION_HH_
#define SDF_EXCEPTION_HH_
#include <cstdint>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <sdf/sdf_config.h>
#include "sdf/system_util.hh"
#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
/// \addtogroup sdf
/// \{
/// \brief This macro logs an error to the throw stream and throws
/// an exception that contains the file name and line number.
#define sdfthrow(msg) {std::ostringstream throwStream;\
throwStream << msg << std::endl << std::flush;\
throw sdf::Exception(__FILE__, __LINE__, throwStream.str()); }
class ExceptionPrivate;
/// \class Exception Exception.hh common/common.hh
/// \brief Class for generating exceptions
class SDFORMAT_VISIBLE Exception
{
/// \brief Constructor
public: Exception();
/// \brief Default constructor
/// \param[in] _file File name
/// \param[in] _line Line number where the error occurred
/// \param[in] _msg Error message
public: Exception(const char *_file,
std::int64_t _line,
std::string _msg);
/// \brief Copy constructor
/// \param[in] _e Exception to copy.
public: Exception(const Exception &_e);
/// \brief Move constructor
/// \param[in] _e Exception to move.
public: Exception(Exception &&_e) noexcept;
/// \brief Assignment operator.
/// \param[in] _exception The exception to set values from.
/// \return *this
public: Exception &operator=(const Exception &_exception);
/// \brief Move assignment operator.
/// \param[in] _exception Exception to move.
/// \return Reference to this.
public: Exception &operator=(Exception &&_exception);
/// \brief Destructor
public: virtual ~Exception();
/// \brief Return the error function
/// \return The error function name
public: std::string GetErrorFile() const;
/// \brief Return the error string
/// \return The error string
public: std::string GetErrorStr() const;
/// \brief Print the exception to std out.
public: void Print() const;
/// \brief stream insertion operator for Gazebo Error
/// \param[in] _out the output stream
/// \param[in] _err the exception
public: friend std::ostream &operator<<(std::ostream& _out,
const sdf::Exception &_err)
{
return _out << _err.GetErrorStr();
}
/// \brief Private data pointer.
private: std::unique_ptr<ExceptionPrivate> dataPtr;
};
/// \class InternalError Exception.hh common/common.hh
/// \brief Class for generating Internal Gazebo Errors:
/// those errors which should never happend and
/// represent programming bugs.
class SDFORMAT_VISIBLE InternalError : public Exception
{
/// \brief Constructor
public: InternalError();
/// \brief Default constructor
/// \param[in] _file File name
/// \param[in] _line Line number where the error occurred
/// \param[in] _msg Error message
public: InternalError(const char *_file, std::int64_t _line,
const std::string _msg);
/// \brief Destructor
public: virtual ~InternalError();
};
/// \class AssertionInternalError Exception.hh common/common.hh
/// \brief Class for generating Exceptions which come from
/// sdf assertions. They include information about the
/// assertion expression violated, function where problem
/// appeared and assertion debug message.
class SDFORMAT_VISIBLE AssertionInternalError : public InternalError
{
/// \brief Constructor for assertions
/// \param[in] _file File name
/// \param[in] _line Line number where the error occurred
/// \param[in] _expr Assertion expression failed resulting in an
/// internal error
/// \param[in] _function Function where assertion failed
/// \param[in] _msg Function where assertion failed
public: AssertionInternalError(const char *_file,
std::int64_t _line,
const std::string _expr,
const std::string _function,
const std::string _msg = "");
/// \brief Destructor
public: virtual ~AssertionInternalError();
};
/// \}
}
}
#ifdef _WIN32
#pragma warning(pop)
#endif
#endif
|