exceptions.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2011, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the copyright holder(s) nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  */
00037 #ifndef PCL_EXCEPTIONS_H_
00038 #define PCL_EXCEPTIONS_H_
00039 
00040 #include <stdexcept>
00041 #include <sstream>
00042 #include <pcl/pcl_macros.h>
00043 #include <boost/current_function.hpp>
00044 
00050 #define PCL_THROW_EXCEPTION(ExceptionName, message)                         \
00051 {                                                                           \
00052   std::ostringstream s;                                                     \
00053   s << message;                                                             \
00054   s.flush ();                                                               \
00055   throw ExceptionName(s.str(), __FILE__, BOOST_CURRENT_FUNCTION, __LINE__); \
00056 }
00057 
00058 namespace pcl
00059 {
00060 
00065   class PCLException : public std::runtime_error
00066   {
00067     public:
00068 
00069       PCLException (const std::string& error_description,
00070                     const std::string& file_name = "",
00071                     const std::string& function_name = "" ,
00072                     unsigned line_number = 0) throw ()
00073         : std::runtime_error (error_description)
00074         , file_name_ (file_name)
00075         , function_name_ (function_name)
00076         , message_ (error_description)
00077         , line_number_ (line_number) 
00078       {
00079         message_ = detailedMessage ();
00080       }
00081       
00082       virtual ~PCLException () throw ()
00083       {}
00084       
00085       const std::string&
00086       getFileName () const throw ()
00087       {
00088         return (file_name_);
00089       }
00090 
00091       const std::string&
00092       getFunctionName () const throw ()
00093       {
00094         return (function_name_);
00095       }
00096 
00097       unsigned
00098       getLineNumber () const throw ()
00099       {
00100         return (line_number_);
00101       }
00102 
00103       std::string 
00104       detailedMessage () const throw ()
00105       {
00106         std::stringstream sstream;
00107         if (function_name_ != "")
00108           sstream << function_name_ << " ";
00109         
00110         if (file_name_ != "")
00111         {
00112           sstream << "in " << file_name_ << " ";
00113           if (line_number_ != 0)
00114             sstream << "@ " << line_number_ << " ";
00115         }
00116         sstream << ": " << what ();
00117         
00118         return (sstream.str ());
00119       }
00120 
00121       char const* 
00122       what () const throw () 
00123       {
00124         return (message_.c_str ());
00125       }
00126 
00127     protected:
00128       std::string file_name_;
00129       std::string function_name_;
00130       std::string message_;
00131       unsigned line_number_;
00132   } ;
00133 
00137   class InvalidConversionException : public PCLException
00138   {
00139     public:
00140 
00141       InvalidConversionException (const std::string& error_description,
00142                                   const std::string& file_name = "",
00143                                   const std::string& function_name = "" ,
00144                                   unsigned line_number = 0) throw ()
00145         : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00146   } ;
00147 
00151   class IsNotDenseException : public PCLException
00152   {
00153     public:
00154 
00155       IsNotDenseException (const std::string& error_description,
00156                            const std::string& file_name = "",
00157                            const std::string& function_name = "" ,
00158                            unsigned line_number = 0) throw ()
00159         : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00160   } ;
00161 
00166   class InvalidSACModelTypeException : public PCLException
00167   {
00168     public:
00169 
00170       InvalidSACModelTypeException (const std::string& error_description,
00171                                     const std::string& file_name = "",
00172                                     const std::string& function_name = "" ,
00173                                     unsigned line_number = 0) throw ()
00174         : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00175   } ;
00176 
00180   class IOException : public PCLException
00181   {
00182     public:
00183 
00184       IOException (const std::string& error_description,
00185                    const std::string& file_name = "",
00186                    const std::string& function_name = "" ,
00187                    unsigned line_number = 0) throw ()
00188         : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00189   } ;
00190 
00195   class InitFailedException : public PCLException
00196   {
00197     public:
00198       InitFailedException (const std::string& error_description = "",
00199                            const std::string& file_name = "",
00200                            const std::string& function_name = "" ,
00201                            unsigned line_number = 0) throw ()
00202         : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00203   } ;
00204 
00209   class UnorganizedPointCloudException : public PCLException
00210   {
00211     public:
00212     
00213       UnorganizedPointCloudException (const std::string& error_description,
00214                                       const std::string& file_name = "",
00215                                       const std::string& function_name = "" ,
00216                                       unsigned line_number = 0) throw ()
00217         : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00218   } ;
00219 
00223   class KernelWidthTooSmallException : public PCLException
00224   {
00225     public:
00226     
00227     KernelWidthTooSmallException (const std::string& error_description,
00228                                   const std::string& file_name = "",
00229                                   const std::string& function_name = "" ,
00230                                   unsigned line_number = 0) throw ()
00231       : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00232   } ;
00233 
00234   class UnhandledPointTypeException : public PCLException
00235   {
00236     public:
00237     UnhandledPointTypeException (const std::string& error_description,
00238                                  const std::string& file_name = "",
00239                                  const std::string& function_name = "" ,
00240                                  unsigned line_number = 0) throw ()
00241       : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00242   };
00243 
00244   class ComputeFailedException : public PCLException
00245   {
00246     public:
00247     ComputeFailedException (const std::string& error_description,
00248                             const std::string& file_name = "",
00249                             const std::string& function_name = "" ,
00250                             unsigned line_number = 0) throw ()
00251       : pcl::PCLException (error_description, file_name, function_name, line_number) { }
00252   };
00253 
00254 }
00255 
00256 
00257 
00258 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:23:36