PCL
Win32Exception.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/Win32Exception.h - Released 2024-01-13T15:47:58Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Win32Exception_h
53 #define __PCL_Win32Exception_h
54 
56 
57 #if !defined( __PCL_WINDOWS ) || defined( __PCL_LINUX ) || defined( __PCL_FREEBSD ) || defined( __PCL_MACOSX )
58 # error Win32Exception can only be used on MS Windows platforms.
59 #endif
60 
61 #include <pcl/Defs.h>
62 
63 #include <pcl/Exception.h>
64 
65 namespace pcl
66 {
67 
68 // ----------------------------------------------------------------------------
69 
84 class PCL_CLASS Win32Exception : public pcl::Exception
85 {
86 public:
87 
92  using exception_address = const void*;
93 
98  using exception_data_pointer = const void*;
99 
103  using exception_code = unsigned;
104 
110  const IsoString& details = IsoString() )
111  : m_code( code )
112  , m_data( data )
113  , m_details( details )
114  {
115  }
116 
120  Win32Exception( const Win32Exception& ) = default;
121 
125  exception_address ExceptionAddress() const;
126 
131  {
132  return m_code;
133  }
134 
141  const IsoString& Details() const
142  {
143  return m_details;
144  }
145 
152  String Message() const override
153  {
154  return "Undefined system exception";
155  }
156 
160  String FormatInfo() const override
161  {
162  String info = String().Format( "At address %p with exception code %X :\n",
163  ExceptionAddress(), ExceptionCode() ) + Message();
164  if ( !m_details.IsEmpty() )
165  {
166  info.Append( '\n' );
167  info.Append( m_details );
168  }
169  return info;
170  }
171 
177  String Caption() const override
178  {
179  return "PCL Win32 System Exception";
180  }
181 
194  void Show() const override;
195 
203  static void Initialize();
204 
205 protected:
206 
207  exception_code m_code;
208  exception_data_pointer m_data; // points to an EXCEPTION_RECORD structure
209  IsoString m_details; // backtrace information
210 };
211 
212 // ----------------------------------------------------------------------------
213 
214 class PCL_CLASS Win32AccessViolationException : public Win32Exception
215 {
216 public:
217 
218  Win32AccessViolationException( exception_code code, exception_data_pointer data,
219  const IsoString& details = IsoString() )
220  : Win32Exception( code, data, details )
221  {
222  }
223 
224  Win32AccessViolationException( const Win32AccessViolationException& ) = default;
225 
226  String Message() const override;
227 };
228 
229 // ----------------------------------------------------------------------------
230 
231 #define DECLARE_WIN32_EXCEPTION( className, message ) \
232  class PCL_CLASS className : public pcl::Win32Exception \
233  { \
234  public: \
235  className( exception_code code, exception_data_pointer data, \
236  const IsoString& details = IsoString() ) : \
237  pcl::Win32Exception( code, data, details ) \
238  { \
239  } \
240  className( const className& ) = default; \
241  String Message() const override \
242  { \
243  return message; \
244  } \
245  }
246 
247 // ----------------------------------------------------------------------------
248 
249 DECLARE_WIN32_EXCEPTION( EWin32ArrayBoundsExceeded,
250  "Array bounds exceeded" );
251 
252 DECLARE_WIN32_EXCEPTION( EWin32Breakpoint,
253  "A breakpoint was encountered" );
254 
255 DECLARE_WIN32_EXCEPTION( EWin32DataMisalignment,
256  "Invalid read/write operation on misaligned data" );
257 
258 DECLARE_WIN32_EXCEPTION( EWin32FloatingPointDenormalOperand,
259  "Denormal operand in floating-point operation" );
260 
261 DECLARE_WIN32_EXCEPTION( EWin32FloatingPointDivideByZero,
262  "Division by zero in floating-point operation" );
263 
264 DECLARE_WIN32_EXCEPTION( EWin32FloatingPointInexactResult,
265  "Inexact result in floating-point operation" );
266 
267 DECLARE_WIN32_EXCEPTION( EWin32FloatingPointInvalidOperation,
268  "Invalid floating-point operation" );
269 
270 DECLARE_WIN32_EXCEPTION( EWin32FloatingPointOverflow,
271  "Overflow in floating-point operation" );
272 
273 DECLARE_WIN32_EXCEPTION( EWin32FloatingPointStackCheck,
274  "Stack limits exceeded in floating-point operation" );
275 
276 DECLARE_WIN32_EXCEPTION( EWin32FloatingPointUnderflow,
277  "Underflow in floating-point operation" );
278 
279 DECLARE_WIN32_EXCEPTION( EWin32IllegalInstruction,
280  "Illegal processor instruction" );
281 
282 DECLARE_WIN32_EXCEPTION( EWin32PageError,
283  "Memory page not found" );
284 
285 DECLARE_WIN32_EXCEPTION( EWin32DivideByZero,
286  "Integer division by zero" );
287 
288 DECLARE_WIN32_EXCEPTION( EWin32Overflow,
289  "Integer overflow" );
290 
291 DECLARE_WIN32_EXCEPTION( EWin32InvalidDisposition,
292  "Invalid exception disposition" );
293 
294 DECLARE_WIN32_EXCEPTION( EWin32NonContinuableException,
295  "Noncontinuable exception " );
296 
297 DECLARE_WIN32_EXCEPTION( EWin32PrivilegedInstruction,
298  "Privileged processor instruction" );
299 
300 DECLARE_WIN32_EXCEPTION( EWin32SingleStep,
301  "Single-instruction step" );
302 
303 DECLARE_WIN32_EXCEPTION( EWin32StackOverflow,
304  "Stack overflow" );
305 
306 // ----------------------------------------------------------------------------
307 
308 #undef DECLARE_WIN32_EXCEPTION
309 
310 // ----------------------------------------------------------------------------
311 
312 } // pcl
313 
314 #endif // __PCL_Win32Exception_h
315 
316 // ----------------------------------------------------------------------------
317 // EOF pcl/Win32Exception.h - Released 2024-01-13T15:47:58Z
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::String
Unicode (UTF-16) string.
Definition: String.h:8112
pcl::Win32Exception::exception_data_pointer
const void * exception_data_pointer
Definition: Win32Exception.h:98
pcl::IsoString
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5424
pcl::Win32Exception::Win32Exception
Win32Exception(exception_code code, exception_data_pointer data, const IsoString &details=IsoString())
Definition: Win32Exception.h:109
pcl::Win32Exception::Details
const IsoString & Details() const
Definition: Win32Exception.h:141
pcl::Win32Exception::ExceptionCode
exception_code ExceptionCode() const
Definition: Win32Exception.h:130
Exception.h
pcl::Win32Exception::FormatInfo
String FormatInfo() const override
Definition: Win32Exception.h:160
pcl::Win32Exception::Caption
String Caption() const override
Definition: Win32Exception.h:177
pcl::Exception
Root base class for all PCL exception classes.
Definition: Exception.h:81
pcl::Win32Exception
A Win32 structured exception handler that throws C++ exceptions.
Definition: Win32Exception.h:84
pcl::Win32Exception::Message
String Message() const override
Definition: Win32Exception.h:152
pcl::Win32Exception::exception_code
unsigned exception_code
Definition: Win32Exception.h:103
pcl::String::Format
String & Format(const_c_string8 fmt,...)
Definition: String.h:11081
Defs.h
pcl::Win32Exception::exception_address
const void * exception_address
Definition: Win32Exception.h:92