comparison OrthancFramework/Sources/OrthancException.h @ 4304:50b0c69b653a

continued abi
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 06 Nov 2020 16:33:52 +0100
parents bf7b9edf6b81
children d9473bd5ed43
comparison
equal deleted inserted replaced
4303:44b53a2c0a13 4304:50b0c69b653a
20 **/ 20 **/
21 21
22 22
23 #pragma once 23 #pragma once
24 24
25 #include "Compatibility.h" 25 #include "Compatibility.h" // For std::unique_ptr<>
26 #include "Enumerations.h" 26 #include "Enumerations.h"
27 #include "Logging.h"
28 #include "OrthancFramework.h" 27 #include "OrthancFramework.h"
29
30 #include <stdint.h>
31 #include <string>
32 #include <memory>
33 28
34 namespace Orthanc 29 namespace Orthanc
35 { 30 {
36 class ORTHANC_PUBLIC OrthancException 31 class ORTHANC_PUBLIC OrthancException
37 { 32 {
45 40
46 // New in Orthanc 1.5.0 41 // New in Orthanc 1.5.0
47 std::unique_ptr<std::string> details_; 42 std::unique_ptr<std::string> details_;
48 43
49 public: 44 public:
50 OrthancException(const OrthancException& other) : 45 OrthancException(const OrthancException& other);
51 errorCode_(other.errorCode_),
52 httpStatus_(other.httpStatus_)
53 {
54 if (other.details_.get() != NULL)
55 {
56 details_.reset(new std::string(*other.details_));
57 }
58 }
59 46
60 explicit OrthancException(ErrorCode errorCode) : 47 explicit OrthancException(ErrorCode errorCode);
61 errorCode_(errorCode),
62 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode))
63 {
64 }
65 48
66 OrthancException(ErrorCode errorCode, 49 OrthancException(ErrorCode errorCode,
67 const std::string& details, 50 const std::string& details,
68 bool log = true) : 51 bool log = true);
69 errorCode_(errorCode),
70 httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)),
71 details_(new std::string(details))
72 {
73 #if ORTHANC_ENABLE_LOGGING == 1
74 if (log)
75 {
76 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
77 }
78 #endif
79 }
80 52
81 OrthancException(ErrorCode errorCode, 53 OrthancException(ErrorCode errorCode,
82 HttpStatus httpStatus) : 54 HttpStatus httpStatus);
83 errorCode_(errorCode),
84 httpStatus_(httpStatus)
85 {
86 }
87 55
88 OrthancException(ErrorCode errorCode, 56 OrthancException(ErrorCode errorCode,
89 HttpStatus httpStatus, 57 HttpStatus httpStatus,
90 const std::string& details, 58 const std::string& details,
91 bool log = true) : 59 bool log = true);
92 errorCode_(errorCode),
93 httpStatus_(httpStatus),
94 details_(new std::string(details))
95 {
96 #if ORTHANC_ENABLE_LOGGING == 1
97 if (log)
98 {
99 LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
100 }
101 #endif
102 }
103 60
104 ErrorCode GetErrorCode() const 61 ErrorCode GetErrorCode() const;
105 {
106 return errorCode_;
107 }
108 62
109 HttpStatus GetHttpStatus() const 63 HttpStatus GetHttpStatus() const;
110 {
111 return httpStatus_;
112 }
113 64
114 const char* What() const 65 const char* What() const;
115 {
116 return EnumerationToString(errorCode_);
117 }
118 66
119 bool HasDetails() const 67 bool HasDetails() const;
120 {
121 return details_.get() != NULL;
122 }
123 68
124 const char* GetDetails() const 69 const char* GetDetails() const;
125 {
126 if (details_.get() == NULL)
127 {
128 return "";
129 }
130 else
131 {
132 return details_->c_str();
133 }
134 }
135 }; 70 };
136 } 71 }