Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exceptions.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 #ifndef PCL_EXCEPTIONS_H_
38 #define PCL_EXCEPTIONS_H_
39 
40 #include <stdexcept>
41 #include <sstream>
42 #include <pcl/pcl_macros.h>
43 
44 namespace pcl
45 {
46 
51  class PCLException : public std::runtime_error
52  {
53  public:
54 
55  PCLException (const std::string& error_description,
56  const std::string& file_name = "",
57  const std::string& function_name = "" ,
58  unsigned line_number = 0) throw ()
59  : std::runtime_error (error_description)
60  , file_name_ (file_name)
61  , function_name_ (function_name)
62  , line_number_ (line_number)
63  {}
64 
65  virtual ~PCLException () throw ()
66  {}
67 
68  const std::string&
69  getFileName () const throw ()
70  {
71  return file_name_;
72  }
73 
74  const std::string&
75  getFunctionName () const throw ()
76  {
77  return function_name_;
78  }
79 
80  unsigned
81  getLineNumber () const throw ()
82  {
83  return line_number_;
84  }
85 
86  std::string
87  detailedMessage () const throw ()
88  {
89  std::stringstream sstream;
90  if (function_name_ != "")
91  sstream << function_name_ << " ";
92 
93  if (file_name_ != "")
94  {
95  sstream << "in " << file_name_ << " ";
96  if (line_number_ != 0)
97  sstream << "@ " << line_number_ << " ";
98  }
99  sstream << ":" << what ();
100 
101  return sstream.str ();
102  }
103 
104  protected:
105  std::string file_name_;
106  std::string function_name_;
107  unsigned line_number_;
108  } ;
109 
114  {
115  public:
116 
117  InvalidConversionException (const std::string& error_description,
118  const std::string& file_name = "",
119  const std::string& function_name = "" ,
120  unsigned line_number = 0) throw ()
121  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
122  } ;
123 
128  {
129  public:
130 
131  IsNotDenseException (const std::string& error_description,
132  const std::string& file_name = "",
133  const std::string& function_name = "" ,
134  unsigned line_number = 0) throw ()
135  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
136  } ;
137 
143  {
144  public:
145 
146  InvalidSACModelTypeException (const std::string& error_description,
147  const std::string& file_name = "",
148  const std::string& function_name = "" ,
149  unsigned line_number = 0) throw ()
150  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
151  } ;
152 
156  class IOException : public PCLException
157  {
158  public:
159 
160  IOException (const std::string& error_description,
161  const std::string& file_name = "",
162  const std::string& function_name = "" ,
163  unsigned line_number = 0) throw ()
164  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
165  } ;
166 
172  {
173  public:
174  InitFailedException (const std::string& error_description = "",
175  const std::string& file_name = "",
176  const std::string& function_name = "" ,
177  unsigned line_number = 0) throw ()
178  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
179  } ;
180 
186  {
187  public:
188 
189  UnorganizedPointCloudException (const std::string& error_description,
190  const std::string& file_name = "",
191  const std::string& function_name = "" ,
192  unsigned line_number = 0) throw ()
193  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
194  } ;
195 
200  {
201  public:
202 
203  KernelWidthTooSmallException (const std::string& error_description,
204  const std::string& file_name = "",
205  const std::string& function_name = "" ,
206  unsigned line_number = 0) throw ()
207  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
208  } ;
209 
211  {
212  public:
213  UnhandledPointTypeException (const std::string& error_description,
214  const std::string& file_name = "",
215  const std::string& function_name = "" ,
216  unsigned line_number = 0) throw ()
217  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
218  };
219 
221  {
222  public:
223  ComputeFailedException (const std::string& error_description,
224  const std::string& file_name = "",
225  const std::string& function_name = "" ,
226  unsigned line_number = 0) throw ()
227  : pcl::PCLException (error_description, file_name, function_name, line_number) { }
228  };
229 
230 }
231 
237 #define PCL_THROW_EXCEPTION(ExceptionName, message) \
238 { \
239  std::ostringstream s; \
240  s << message; \
241  throw ExceptionName(s.str(), __FILE__, "", __LINE__); \
242 }
243 
244 #endif