Upx_Doxygen
https://github.com/upx/upx
except.h
1 /* except.h --
2 
3  This file is part of the UPX executable compressor.
4 
5  Copyright (C) 1996-2016 Markus Franz Xaver Johannes Oberhumer
6  Copyright (C) 1996-2016 Laszlo Molnar
7  All Rights Reserved.
8 
9  UPX and the UCL library are free software; you can redistribute them
10  and/or modify them under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of
12  the License, or (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING.
21  If not, write to the Free Software Foundation, Inc.,
22  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Markus F.X.J. Oberhumer Laszlo Molnar
25  <markus@oberhumer.com> <ezerotven+github@gmail.com>
26  */
27 
28 
29 #ifndef __UPX_EXCEPT_H
30 #define __UPX_EXCEPT_H 1
31 
32 #ifdef __cplusplus
33 
34 const char *prettyName(const char *n) NOTHROW;
35 
36 
37 /*************************************************************************
38 // exceptions
39 **************************************************************************/
40 
41 class Throwable : public std::exception
42 {
43  typedef std::exception super;
44 protected:
45  Throwable(const char *m = 0, int e = 0, bool w = false) NOTHROW;
46 public:
47  Throwable(const Throwable &) NOTHROW;
48  virtual ~Throwable() NOTHROW;
49  const char *getMsg() const NOTHROW { return msg; }
50  int getErrno() const NOTHROW { return err; }
51  bool isWarning() const NOTHROW { return is_warning; }
52 private:
53  char *msg;
54  int err;
55 protected:
56  bool is_warning; // can be set by subclasses
57 
58 private:
59  // disable assignment
60  Throwable& operator= (const Throwable &);
61  // disable dynamic allocation
62  DISABLE_NEW_DELETE
63 
64 private:
65  static unsigned long counter; // for debugging
66 };
67 
68 
69 // Exceptions can/should be caught
70 class Exception : public Throwable
71 {
72  typedef Throwable super;
73 public:
74  Exception(const char *m = 0, int e = 0, bool w = false) NOTHROW : super(m,e,w) { }
75 };
76 
77 
78 // Errors should not be caught (or re-thrown)
79 class Error : public Throwable
80 {
81  typedef Throwable super;
82 public:
83  Error(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
84 };
85 
86 
87 /*************************************************************************
88 // system exception
89 **************************************************************************/
90 
91 class OutOfMemoryException : public Exception
92 {
93  typedef Exception super;
94 public:
95  OutOfMemoryException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
96 };
97 
98 
99 class IOException : public Exception
100 {
101  typedef Exception super;
102 public:
103  IOException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
104 };
105 
106 
107 class EOFException : public IOException
108 {
109  typedef IOException super;
110 public:
111  EOFException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
112 };
113 
114 
115 class FileNotFoundException : public IOException
116 {
117  typedef IOException super;
118 public:
119  FileNotFoundException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
120 };
121 
122 
123 class FileAlreadyExistsException : public IOException
124 {
125  typedef IOException super;
126 public:
127  FileAlreadyExistsException(const char *m = 0, int e = 0) NOTHROW : super(m,e) { }
128 };
129 
130 
131 /*************************************************************************
132 // application execptions
133 **************************************************************************/
134 
135 class OverlayException : public Exception
136 {
137  typedef Exception super;
138 public:
139  OverlayException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
140 };
141 
142 class CantPackException : public Exception
143 {
144  typedef Exception super;
145 public:
146  CantPackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
147 };
148 
149 class UnknownExecutableFormatException : public CantPackException
150 {
151  typedef CantPackException super;
152 public:
153  UnknownExecutableFormatException(const char *m = 0, bool w = false) NOTHROW : super(m,w) { }
154 };
155 
156 class AlreadyPackedException : public CantPackException
157 {
158  typedef CantPackException super;
159 public:
160  AlreadyPackedException(const char *m = 0) NOTHROW : super(m) { is_warning = true; }
161 };
162 
163 class NotCompressibleException : public CantPackException
164 {
165  typedef CantPackException super;
166 public:
167  NotCompressibleException(const char *m = 0) NOTHROW : super(m) { }
168 };
169 
170 
171 class CantUnpackException : public Exception
172 {
173  typedef Exception super;
174 public:
175  CantUnpackException(const char *m = 0, bool w = false) NOTHROW : super(m,0,w) { }
176 };
177 
178 class NotPackedException : public CantUnpackException
179 {
180  typedef CantUnpackException super;
181 public:
182  NotPackedException(const char *m = 0) NOTHROW : super(m,true) { }
183 };
184 
185 
186 /*************************************************************************
187 // errors
188 **************************************************************************/
189 
190 class InternalError : public Error
191 {
192  typedef Error super;
193 public:
194  InternalError(const char *m = 0) NOTHROW : super(m,0) { }
195 };
196 
197 
198 /*************************************************************************
199 // util
200 **************************************************************************/
201 
202 #undef NORET
203 #if 1 && defined(__GNUC__)
204 #define NORET __attribute__((__noreturn__))
205 #else
206 #define NORET /*empty*/
207 #endif
208 
209 void throwCantPack(const char *msg) NORET;
210 void throwCantPackExact() NORET;
211 void throwUnknownExecutableFormat(const char *msg = NULL, bool warn = false) NORET;
212 void throwNotCompressible(const char *msg = NULL) NORET;
213 void throwAlreadyPacked(const char *msg = NULL) NORET;
214 void throwAlreadyPackedByUPX(const char *msg = NULL) NORET;
215 void throwCantUnpack(const char *msg) NORET;
216 void throwNotPacked(const char *msg = NULL) NORET;
217 void throwFilterException() NORET;
218 void throwBadLoader() NORET;
219 void throwChecksumError() NORET;
220 void throwCompressedDataViolation() NORET;
221 void throwInternalError(const char *msg) NORET;
222 void throwOutOfMemoryException(const char *msg = NULL) NORET;
223 void throwIOException(const char *msg = NULL, int e = 0) NORET;
224 void throwEOFException(const char *msg = NULL, int e = 0) NORET;
225 
226 #undef NORET
227 
228 
229 #endif /* __cplusplus */
230 
231 #endif /* already included */
232 
233 /* vim:set ts=4 sw=4 et: */