Exception.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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  * Author: Nathan Koenig
19  * Date: 07 May 2007
20  */
21 
22 #ifndef _GAZEBO_EXCEPTION_HH_
23 #define _GAZEBO_EXCEPTION_HH_
24 
25 #include <iostream>
26 #include <sstream>
27 #include <string>
28 #include "gazebo/util/system.hh"
29 
30 namespace gazebo
31 {
32  namespace common
33  {
36 
39  #define gzthrow(msg) {std::ostringstream throwStream;\
40  throwStream << msg << std::endl << std::flush;\
41  throw gazebo::common::Exception(__FILE__, __LINE__, throwStream.str()); }
42 
46  {
48  public: Exception();
49 
54  public: Exception(const char *_file,
55  int _line,
56  std::string _msg);
57 
59  public: virtual ~Exception();
60 
63  public: std::string GetErrorFile() const;
64 
67  public: std::string GetErrorStr() const;
68 
70  public: void Print() const;
71 
73  private: std::string file;
74 
76  private: int line;
77 
79  private: std::string str;
80 
84  public: friend std::ostream &operator<<(std::ostream &_out,
85  const gazebo::common::Exception &_err)
86  {
87  return _out << _err.GetErrorStr();
88  }
89  };
90 
96  {
98  public: InternalError();
99 
104  public: InternalError(const char *_file, int _line,
105  const std::string &_msg);
106 
108  public: virtual ~InternalError();
109  };
110 
117  {
125  public: AssertionInternalError(const char *_file,
126  int _line,
127  const std::string &_expr,
128  const std::string &_function,
129  const std::string &_msg = "");
131  public: virtual ~AssertionInternalError();
132  };
134  }
135 }
136 
137 #endif
#define GZ_COMMON_VISIBLE
Definition: system.hh:84
Class for generating Exceptions which come from gazebo assertions.
Definition: Exception.hh:116
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Exception &_err)
stream insertion operator for Gazebo Error
Definition: Exception.hh:84
std::string GetErrorStr() const
Return the error string.
Class for generating Internal Gazebo Errors: those errors which should never happend and represent pr...
Definition: Exception.hh:95
Class for generating exceptions.
Definition: Exception.hh:45