All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Exception.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Nate Koenig
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 
29 namespace gazebo
30 {
31  namespace common
32  {
35 
38  #define gzthrow(msg) {std::ostringstream throwStream;\
39  throwStream << msg << std::endl << std::flush;\
40  throw gazebo::common::Exception(__FILE__, __LINE__, throwStream.str()); }
41 
44  class Exception
45  {
47  public: Exception();
48 
53  public: Exception(const char *_file,
54  int _line,
55  std::string _msg);
56 
58  public: virtual ~Exception();
59 
62  public: std::string GetErrorFile() const;
63 
66  public: std::string GetErrorStr() const;
67 
69  public: void Print() const;
70 
72  private: std::string file;
73 
75  private: int line;
76 
78  private: std::string str;
79 
83  public: friend std::ostream &operator<<(std::ostream& _out,
84  const gazebo::common::Exception &_err)
85  {
86  return _out << _err.GetErrorStr();
87  }
88  };
90  }
91 }
92 
93 #endif