Point Cloud Library (PCL)  1.14.1-dev
openni_exception.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011 Willow Garage, Inc.
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the copyright holder(s) nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 
37 #pragma once
38 
39 #include <pcl/pcl_config.h>
40 #ifdef HAVE_OPENNI
41 
42 #include <cstdarg>
43 #include <cstdio>
44 #include <exception>
45 #include <string>
46 //#include <pcl/pcl_macros.h> <-- because current header is included in NVCC-compiled code and contains <Eigen/Core>. Consider <pcl/pcl_exports.h>
47 
48 
49 //from <pcl/pcl_macros.h>
50 #if defined _WIN32 && defined _MSC_VER && !defined __PRETTY_FUNCTION__
51  #define __PRETTY_FUNCTION__ __FUNCTION__
52 #endif
53 
54 
55 #define THROW_OPENNI_EXCEPTION(format,...) throwOpenNIException( __PRETTY_FUNCTION__, __FILE__, __LINE__, format , ##__VA_ARGS__ )
56 
57 
58 namespace openni_wrapper
59 {
60 
61  /**
62  * @brief General exception class
63  * @author Suat Gedikli
64  * @date 02.january 2011
65  * @ingroup io
66  */
67  class OpenNIException : public std::exception
68  {
69  public:
70  /**
71  * @brief Constructor
72  * @note use the MACRO THROW_OPENNI_EXCEPTION, that takes care about the parameters function_name, file_name and line_number
73  * @param[in] function_name the function in which this exception was created.
74  * @param[in] file_name the file name in which this exception was created.
75  * @param[in] line_number the line number where this exception was created.
76  * @param[in] message the message of the exception
77  */
78  OpenNIException (const std::string& function_name, const std::string& file_name, unsigned line_number, const std::string& message) noexcept;
79 
80  /**
81  * @brief virtual Destructor that never throws an exception
82  */
83  ~OpenNIException () noexcept override;
84 
85  /**
86  * @brief Assignment operator to allow copying the message of another exception variable.
87  * @param[in] exception left hand side
88  * @return
89  */
90  OpenNIException & operator= (const OpenNIException& exception) noexcept;
91 
92  /**
93  * @brief virtual method, derived from std::exception
94  * @return the message of the exception.
95  */
96  const char* what () const noexcept override;
97 
98  /**
99  * @return the function name in which the exception was created.
100  */
101  const std::string& getFunctionName () const noexcept;
102 
103  /**
104  * @return the filename in which the exception was created.
105  */
106  const std::string& getFileName () const noexcept;
107 
108  /**
109  * @return the line number where the exception was created.
110  */
111  unsigned getLineNumber () const noexcept;
112  protected:
113  std::string function_name_;
114  std::string file_name_;
115  unsigned line_number_;
116  std::string message_;
117  std::string message_long_;
118  } ;
119 
120  /**
121  * @brief inline function used by the macro THROW_OPENNI_EXCEPTION to create an instance of OpenNIException with correct values for function, file and line_number
122  * @param[in] function_name the function name. Will be filled in by the macro THROW_OPENNI_EXCEPTION
123  * @param[in] file_name the file name. Will be filled in by the macro THROW_OPENNI_EXCEPTION
124  * @param[in] line_number the line number. Will be filled in by the macro THROW_OPENNI_EXCEPTION
125  * @param[in] format the printf-style format string
126  * @param[in] ... optional arguments for the printf style format.
127  */
128  inline void
129  throwOpenNIException (const char* function_name, const char* file_name, unsigned line_number, const char* format, ...)
130  {
131  static char msg[1024];
132  va_list args;
133  va_start (args, format);
134  vsprintf (msg, format, args);
135  va_end (args);
136  throw OpenNIException (function_name, file_name, line_number, msg);
137  }
138 } // namespace openni_camera
139 #endif
General exception class.
~OpenNIException() noexcept override
virtual Destructor that never throws an exception
OpenNIException(const std::string &function_name, const std::string &file_name, unsigned line_number, const std::string &message) noexcept
Constructor.
const std::string & getFileName() const noexcept
unsigned getLineNumber() const noexcept
const char * what() const noexcept override
virtual method, derived from std::exception
const std::string & getFunctionName() const noexcept
void throwOpenNIException(const char *function_name, const char *file_name, unsigned line_number, const char *format,...)
inline function used by the macro THROW_OPENNI_EXCEPTION to create an instance of OpenNIException wit...