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 2011 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 
43  class Exception
44  {
46  public: Exception();
47 
52  public: Exception(const char *file,
53  int line,
54  std::string msg);
55 
57  public: virtual ~Exception();
58 
61  public: std::string GetErrorFile() const;
62 
65  public: std::string GetErrorStr() const;
66 
68  private: std::string file;
69 
71  private: int line;
72 
74  private: std::string str;
75 
79  public: friend std::ostream &operator<<(std::ostream& _out,
80  const gazebo::common::Exception &_err)
81  {
82  return _out << _err.GetErrorStr();
83  }
84  };
86  }
87 }
88 
89 #endif