Point Cloud Library (PCL) 1.12.0
Loading...
Searching...
No Matches
poisson_exceptions.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2019-, Open Perception, 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 the copyright holder(s) 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
38#pragma once
39
40#include <stdexcept>
41#include <sstream>
42#include <boost/current_function.hpp>
43
44/** POISSON_THROW_EXCEPTION is a helper macro to be used for throwing exceptions. e.g.
45 * POISSON_THROW_EXCEPTION (PoissonBadArgumentException, "[ERROR] B-spline up-sampling not supported for degree " << Degree);
46 *
47 * \note
48 * Adapted from PCL_THROW_EXCEPTION. We intentionally do not reuse PCL_THROW_EXCEPTION here
49 * to avoid introducing any dependencies on PCL in this 3rd party module.
50 */
51#define POISSON_THROW_EXCEPTION(ExceptionName, message) \
52{ \
53 std::ostringstream s; \
54 s << message; \
55 throw ExceptionName(s.str(), __FILE__, BOOST_CURRENT_FUNCTION, __LINE__); \
56}
57
58namespace pcl
59{
60 namespace poisson
61 {
62 /** \class PoissonException
63 * \brief A base class for all poisson exceptions which inherits from std::runtime_error
64 *
65 * \note
66 * Adapted from PCLException. We intentionally do not reuse PCLException here
67 * to avoid introducing any dependencies on PCL in this 3rd party module.
68 */
69 class PoissonException : public std::runtime_error
70 {
71 public:
72 PoissonException (const std::string& error_description,
73 const char* file_name = nullptr,
74 const char* function_name = nullptr,
75 unsigned line_number = 0)
76 : std::runtime_error (createDetailedMessage (error_description,
77 file_name,
78 function_name,
79 line_number))
80 , file_name_ (file_name)
81 , function_name_ (function_name)
82 , line_number_ (line_number)
83 {}
84
85 protected:
86 static std::string
87 createDetailedMessage (const std::string& error_description,
88 const char* file_name,
89 const char* function_name,
90 unsigned line_number)
91 {
92 std::ostringstream sstream;
93 if (function_name)
94 sstream << function_name << ' ';
95
96 if (file_name)
97 {
98 sstream << "in " << file_name << ' ';
99 if (line_number)
100 sstream << "@ " << line_number << ' ';
101 }
102 sstream << ": " << error_description;
103
104 return (sstream.str ());
105 }
106
107 const char* file_name_;
108 const char* function_name_;
109 unsigned line_number_;
110 };
111
112 /** \class PoissonBadArgumentException
113 * \brief An exception that is thrown when the arguments number or type is wrong/unhandled.
114 */
116 {
117 public:
118 PoissonBadArgumentException (const std::string& error_description,
119 const char* file_name = nullptr,
120 const char* function_name = nullptr,
121 unsigned line_number = 0)
122 : pcl::poisson::PoissonException (error_description, file_name, function_name, line_number) {}
123 };
124
125 /** \class PoissonOpenMPException
126 * \brief An exception that is thrown when something goes wrong inside an openMP for loop.
127 */
129 {
130 public:
131 PoissonOpenMPException (const std::string& error_description,
132 const char* file_name = nullptr,
133 const char* function_name = nullptr,
134 unsigned line_number = 0)
135 : pcl::poisson::PoissonException (error_description, file_name, function_name, line_number) {}
136 };
137
138 /** \class PoissonBadInitException
139 * \brief An exception that is thrown when initialization fails.
140 */
142 {
143 public:
144 PoissonBadInitException (const std::string& error_description,
145 const char* file_name = nullptr,
146 const char* function_name = nullptr,
147 unsigned line_number = 0)
148 : pcl::poisson::PoissonException (error_description, file_name, function_name, line_number) {}
149 };
150 }
151}
An exception that is thrown when the arguments number or type is wrong/unhandled.
PoissonBadArgumentException(const std::string &error_description, const char *file_name=nullptr, const char *function_name=nullptr, unsigned line_number=0)
An exception that is thrown when initialization fails.
PoissonBadInitException(const std::string &error_description, const char *file_name=nullptr, const char *function_name=nullptr, unsigned line_number=0)
A base class for all poisson exceptions which inherits from std::runtime_error.
PoissonException(const std::string &error_description, const char *file_name=nullptr, const char *function_name=nullptr, unsigned line_number=0)
static std::string createDetailedMessage(const std::string &error_description, const char *file_name, const char *function_name, unsigned line_number)
An exception that is thrown when something goes wrong inside an openMP for loop.
PoissonOpenMPException(const std::string &error_description, const char *file_name=nullptr, const char *function_name=nullptr, unsigned line_number=0)