comparison Utils/Exception.h @ 1:0b3630a29ad8

Initial version based on previous repository. Project was ported to QT6 and in now cmake based.
author Ideenmodellierer <tiefenrauscher@web.de>
date Thu, 27 Nov 2025 18:40:28 +0100
parents
children 177f640940f2
comparison
equal deleted inserted replaced
0:76ccd6ce50c0 1:0b3630a29ad8
1 //////////////////////////////////////////////////////////////////////////////
2 /// \file Exception.h
3 /// \brief Generic Exception.
4 /// \author JD Gascuel.
5 /// \copyright (c) 2011-2016 JD Gascuel. All rights reserved.
6 /// $Id$
7 //////////////////////////////////////////////////////////////////////////////
8 //
9 // BSD 2-Clause License:
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions
13 // are met:
14 //
15 // 1. Redistributions of source code must retain the above copyright notice,
16 // this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright notice,
19 // this list of conditions and the following disclaimer in the documentation
20 // and/or other materials provided with the distribution.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 // THE POSSIBILITY OF SUCH DAMAGE.
33 //
34 //////////////////////////////////////////////////////////////////////////////
35 // HISTORY
36 // 2013-12-21 jDG: Creation.
37 // 2016-05-24 jDG: BSD-2 version.
38
39 #ifndef EXCEPTION_H
40 #define EXCEPTION_H
41
42 #include <QString>
43 #include <exception>
44
45 //////////////////////////////////////////////////////////////////////////////
46 #define BUILD_OSTC_COMPANION 1
47
48 #if defined(BUILD_OSTC_COMPANION)
49 # define EXPORT __declspec(dllexport)
50 #else
51 # define EXPORT __declspec(dllimport)
52 #endif
53
54 class EXPORT Exception
55 : public std::exception
56 {
57 const char* const _msg;
58 public:
59 explicit Exception(const char* msg);
60 explicit Exception(const QString& msg);
61
62 // Final cleanup.
63 ~Exception() throw() override;
64
65 /// Message contains, in UTF8 format.
66 const char* what() const throw() override;
67 };
68
69 //////////////////////////////////////////////////////////////////////////////
70
71 #define DEFINE_EXCEPTION(name, parent) \
72 struct EXPORT name \
73 : public parent \
74 { explicit inline name(const char* msg) : parent(msg) {} \
75 explicit inline name(const QString& msg): parent(msg) {} \
76 }
77
78 DEFINE_EXCEPTION(Timeout, Exception);
79 DEFINE_EXCEPTION(ReadTimeout, Timeout);
80 DEFINE_EXCEPTION(WriteTimeout, Timeout);
81
82 #endif // EXCEPTION_H