Exception.hh
00001 /* 00002 * Copyright 2011 Nate Koenig & Andrew Howard 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 /* 00018 * Desc: Gazebo Error 00019 * Author: Nathan Koenig 00020 * Date: 07 May 2007 00021 */ 00022 00023 #ifndef GAZEBO_EXCEPTION_HH 00024 #define GAZEBO_EXCEPTION_HH 00025 00026 #include <iostream> 00027 #include <sstream> 00028 #include <string> 00029 00030 namespace gazebo 00031 { 00032 namespace common 00033 { 00036 00038 #define gzthrow(msg) {std::ostringstream throwStream; throwStream << msg << std::endl << std::flush; throw gazebo::common::Exception(__FILE__,__LINE__,throwStream.str()); } 00039 00040 00042 class Exception 00043 { 00045 public: Exception(); 00046 00051 public: Exception(const char *file, 00052 int line, 00053 std::string msg); 00054 00056 public: virtual ~Exception(); 00057 00060 public: std::string GetErrorFile() const; 00061 00064 public: std::string GetErrorStr() const; 00065 00067 private: std::string file; 00068 00070 private: int line; 00071 00073 private: std::string str; 00074 00076 public: friend std::ostream &operator<<(std::ostream& out, 00077 const gazebo::common::Exception &err) 00078 { 00079 return out << err.GetErrorStr(); 00080 } 00081 }; 00083 } 00084 } 00085 00086 #endif

1.7.5.1