1 /*
2 * Copyright 2013-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include <package/manager/Exceptions.h>
8
9 #include <stdarg.h>
10
11
12 namespace BPackageKit {
13
14 namespace BManager {
15
16 namespace BPrivate {
17
18
19 // #pragma mark - BException
20
21
BException()22 BException::BException()
23 :
24 fMessage()
25 {
26 }
27
28
BException(const BString & message)29 BException::BException(const BString& message)
30 :
31 fMessage(message)
32 {
33 }
34
35
36 // #pragma mark - BFatalErrorException
37
38
BFatalErrorException()39 BFatalErrorException::BFatalErrorException()
40 :
41 BException(),
42 fDetails(),
43 fError(B_OK),
44 fCommitTransactionResult(),
45 fCommitTransactionFailed(false)
46 {
47 }
48
49
BFatalErrorException(const char * format,...)50 BFatalErrorException::BFatalErrorException(const char* format, ...)
51 :
52 BException(),
53 fDetails(),
54 fError(B_OK),
55 fCommitTransactionResult(),
56 fCommitTransactionFailed(false)
57 {
58 va_list args;
59 va_start(args, format);
60 fMessage.SetToFormatVarArgs(format, args);
61 va_end(args);
62 }
63
64
BFatalErrorException(status_t error,const char * format,...)65 BFatalErrorException::BFatalErrorException(status_t error, const char* format,
66 ...)
67 :
68 BException(),
69 fDetails(),
70 fError(error),
71 fCommitTransactionResult(),
72 fCommitTransactionFailed(false)
73 {
74 va_list args;
75 va_start(args, format);
76 fMessage.SetToFormatVarArgs(format, args);
77 va_end(args);
78 }
79
80
BFatalErrorException(const BCommitTransactionResult & result)81 BFatalErrorException::BFatalErrorException(
82 const BCommitTransactionResult& result)
83 :
84 BException(),
85 fDetails(),
86 fError(B_OK),
87 fCommitTransactionResult(result),
88 fCommitTransactionFailed(true)
89 {
90 fMessage.SetToFormat("failed to commit transaction: %s",
91 result.FullErrorMessage().String());
92 }
93
94
95 BFatalErrorException&
SetDetails(const BString & details)96 BFatalErrorException::SetDetails(const BString& details)
97 {
98 fDetails = details;
99 return *this;
100 }
101
102
103 // #pragma mark - BAbortedByUserException
104
105
BAbortedByUserException()106 BAbortedByUserException::BAbortedByUserException()
107 :
108 BException()
109 {
110 }
111
112
113 // #pragma mark - BNothingToDoException
114
115
BNothingToDoException()116 BNothingToDoException::BNothingToDoException()
117 :
118 BException()
119 {
120 }
121
122
123 } // namespace BPrivate
124
125 } // namespace BManager
126
127 } // namespace BPackageKit
128