Revert r28121 as it removes an optimization
[reactos.git] / reactos / tools / rbuild / exception.cpp
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #include "pch.h"
19 #include "rbuild.h"
20
21 using std::string;
22
23 Exception::Exception ()
24 {
25 }
26
27 Exception::Exception ( const string& message )
28 {
29 _e = message;
30 }
31
32 Exception::Exception ( const char* format, ...)
33 {
34 va_list args;
35 va_start ( args, format);
36 _e = ssvprintf ( format, args);
37 va_end ( args );
38 }
39
40 void Exception::SetMessage ( const char* format, ...)
41 {
42 va_list args;
43 va_start ( args, format);
44 _e = ssvprintf ( format, args);
45 va_end ( args );
46 }
47
48 void Exception::SetMessageV ( const char* message, va_list args )
49 {
50 _e = ssvprintf ( message, args);
51 }
52
53
54 OutOfMemoryException::OutOfMemoryException ()
55 : Exception ( "Out of memory" )
56 {
57 }
58
59
60 InvalidOperationException::InvalidOperationException (
61 const char* filename,
62 const int linenumber )
63 : Exception ( "%s:%d", filename, linenumber )
64 {
65 }
66
67 InvalidDateException::InvalidDateException ( const string& filename)
68 : Exception ( "File '%s' has an invalid date.",
69 filename.c_str() )
70 {
71 Filename = filename;
72 }
73
74 InvalidOperationException::InvalidOperationException (
75 const char* filename,
76 const int linenumber,
77 const char* message,
78 ... )
79 {
80 string errorMessage;
81 va_list args;
82 va_start ( args, message );
83 errorMessage = ssvprintf ( message, args );
84 va_end ( args );
85 SetMessage (
86 "%s:%d %s",
87 filename,
88 linenumber,
89 errorMessage.c_str () );
90 }
91
92
93 FileNotFoundException::FileNotFoundException ( const string& filename )
94 : Exception ( "File '%s' not found.",
95 filename.c_str() )
96 {
97 Filename = filename;
98 }
99
100
101 AccessDeniedException::AccessDeniedException ( const string& filename)
102 : Exception ( "Access denied to file or directory '%s'.",
103 filename.c_str() )
104 {
105 Filename = filename;
106 }
107
108
109 RequiredAttributeNotFoundException::RequiredAttributeNotFoundException (
110 const string& location,
111 const string& attributeName,
112 const string& elementName )
113 : XMLInvalidBuildFileException (
114 location,
115 "Required attribute '%s' not found on '%s'.",
116 attributeName.c_str (),
117 elementName.c_str ())
118 {
119 }
120
121 InvalidAttributeValueException::InvalidAttributeValueException (
122 const string& location,
123 const string& name,
124 const string& value )
125 : XMLInvalidBuildFileException (
126 location,
127 "Attribute '%s' has an invalid value '%s'.",
128 name.c_str (),
129 value.c_str () )
130 {
131
132 }
133
134 BackendNameConflictException::BackendNameConflictException ( const string& name )
135 : Exception ( "Backend name conflict: '%s'",
136 name.c_str() )
137 {
138 }
139
140
141 UnknownBackendException::UnknownBackendException ( const string& name )
142 : Exception ( "Unknown Backend requested: '%s'",
143 name.c_str() )
144 {
145 }
146
147
148 UnknownModuleTypeException::UnknownModuleTypeException ( const string& location,
149 int moduletype )
150 : XMLInvalidBuildFileException (
151 location,
152 "module type requested: %i",
153 moduletype )
154 {
155 }
156
157
158 InvocationFailedException::InvocationFailedException ( const std::string& command,
159 int exitcode )
160 : Exception ( "Failed to execute '%s' (exit code %d)",
161 command.c_str (),
162 exitcode )
163 {
164 Command = command;
165 ExitCode = exitcode;
166 }
167
168
169 UnsupportedBuildToolException::UnsupportedBuildToolException ( const std::string& buildTool,
170 const std::string& version )
171 : Exception ( "Build tool '%s' with version '%s' is unsupported. Please upgrade your build tool.",
172 buildTool.c_str (),
173 version.c_str () )
174 {
175 BuildTool = buildTool;
176 Version = version;
177 }