retdec
unpacker_exception.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_UNPACKER_RETDEC_UNPACKER_EXCEPTION_H
8 #define RETDEC_UNPACKER_RETDEC_UNPACKER_EXCEPTION_H
9 
10 #include <exception>
11 #include <sstream>
12 #include <string>
13 
14 namespace retdec {
15 namespace unpacker {
16 
20 class UnpackerException : public std::exception
21 {
22 public:
29  {
30  }
31 
37  virtual const char* what() const noexcept override
38  {
39  return _msg.c_str();
40  }
41 
47  const std::string& getMessage() const noexcept
48  {
49  return _msg;
50  }
51 
52 protected:
53  template <typename... Args> explicit UnpackerException(const Args&... args)
54  {
55  std::stringstream ss;
56  buildMessage(ss, args...);
57  _msg = ss.str();
58  }
59 
60 private:
61  template <typename T, typename... Args> void buildMessage(std::stringstream& ss, const T& data, const Args&... args)
62  {
63  ss << data;
64  buildMessage(ss, args...);
65  }
66 
67  void buildMessage(std::stringstream& /*ss*/)
68  {
69  }
70 
71  std::string _msg;
72 };
73 
79 {
80 public:
81  template <typename... Args> FatalException(const Args&... args) : UnpackerException(args...) {}
82 };
83 
88 {
89 public:
90  template <typename... Args> UnsupportedInputException(const Args&... args) : UnpackerException(args...) {}
91 };
92 
99 {
100 public:
101  UnsupportedFileException() : UnsupportedInputException("Input file is in unsupported format.") {}
102 };
103 
108 {
109 public:
110  DecompressionFailedException() : FatalException("Failed to decompress compressed data.") {}
111 };
112 
119 {
120 public:
121  UnsupportedStubException() : UnsupportedInputException("Unsupported unpacking stub detected.") {}
122 };
123 
128 {
129 public:
130  NoEntryPointException() : FatalException("No entry point segment found.") {}
131 };
132 
133 } // namespace unpacker
134 } // namespace retdec
135 
136 #endif
Definition: unpacker_exception.h:108
DecompressionFailedException()
Definition: unpacker_exception.h:110
Definition: unpacker_exception.h:79
FatalException(const Args &... args)
Definition: unpacker_exception.h:81
Definition: unpacker_exception.h:128
NoEntryPointException()
Definition: unpacker_exception.h:130
Definition: unpacker_exception.h:21
virtual const char * what() const noexcept override
Definition: unpacker_exception.h:37
void buildMessage(std::stringstream &)
Definition: unpacker_exception.h:67
UnpackerException(const UnpackerException &ex)
Definition: unpacker_exception.h:28
void buildMessage(std::stringstream &ss, const T &data, const Args &... args)
Definition: unpacker_exception.h:61
UnpackerException(const Args &... args)
Definition: unpacker_exception.h:53
const std::string & getMessage() const noexcept
Definition: unpacker_exception.h:47
std::string _msg
Exception message.
Definition: unpacker_exception.h:71
Definition: unpacker_exception.h:99
UnsupportedFileException()
Definition: unpacker_exception.h:101
Definition: unpacker_exception.h:88
UnsupportedInputException(const Args &... args)
Definition: unpacker_exception.h:90
Definition: unpacker_exception.h:119
UnsupportedStubException()
Definition: unpacker_exception.h:121
Definition: archive_wrapper.h:19
Supportive functionality for the generic unpacker.