(file) Return to Exception.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 mike  1.22 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3 kumpf 1.42 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4            // The Open Group, Tivoli Systems
  5 mike  1.22 //
  6            // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 chip  1.39 // of this software and associated documentation files (the "Software"), to
  8            // deal in the Software without restriction, including without limitation the
  9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10 mike  1.22 // sell copies of the Software, and to permit persons to whom the Software is
 11            // furnished to do so, subject to the following conditions:
 12 kumpf 1.42 // 
 13 chip  1.39 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16 chip  1.39 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19 mike  1.22 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21            //
 22            //==============================================================================
 23            //
 24            // Author: Mike Brasher (mbrasher@bmc.com)
 25            //
 26 mike  1.23 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
 27            //
 28 kumpf 1.29 // Modified By: Jenny Yu (jenny_yu@am.exch.hp.com)
 29 kumpf 1.43 //              Carol Ann Krug Graves, Hewlett-Packard Company
 30            //                (carolann_graves@hp.com)
 31 mike  1.22 //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            #include <cstdio>
 35            #include "Exception.h"
 36 kumpf 1.33 #include "Tracer.h"
 37 mike  1.22 
 38            PEGASUS_NAMESPACE_BEGIN
 39            
 40 chip  1.39 Exception::Exception(const String& message) : _message(message)
 41            {
 42 mike  1.22 
 43            }
 44            
 45 chip  1.39 Exception::Exception(const char* message) : _message(message)
 46 mike  1.22 {
 47            
 48            }
 49            
 50            Exception::~Exception()
 51            {
 52            
 53            }
 54            
 55            AssertionFailureException::AssertionFailureException(
 56 chip  1.39     const char* file,
 57 mike  1.22     size_t line,
 58                const String& message) : Exception(String())
 59            {
 60                char lineStr[32];
 61 kumpf 1.30     sprintf(lineStr, "%u", line);
 62 mike  1.22 
 63                _message = file;
 64                _message.append("(");
 65                _message.append(lineStr);
 66                _message.append("): ");
 67                _message.append(message);
 68 kumpf 1.33 
 69                // ATTN-RK-P3-20020408: Should define a "test" trace component
 70                PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, _message);
 71 mike  1.22 }
 72            
 73            const char OutOfBounds::MSG[] = "out of bounds";
 74            
 75            const char AlreadyExists::MSG[] = "already exists: ";
 76            
 77            const char NullPointer::MSG[] = "null pointer";
 78            
 79 kumpf 1.38 const char UninitializedHandle::MSG[] = "uninitialized handle";
 80 mike  1.22 
 81 kumpf 1.45 const char UninitializedObject::MSG[] = "uninitialized object";
 82            
 83 mike  1.22 const char IllegalName::MSG[] = "illegal CIM name";
 84            
 85 kumpf 1.44 const char IllegalNamespaceName::MSG[] = "illegal CIM namespace name";
 86            
 87 mike  1.22 const char InvalidPropertyOverride::MSG[] = "invalid property override: ";
 88            
 89            const char InvalidMethodOverride::MSG[] = "invalid method override: ";
 90            
 91            const char UndeclaredQualifier::MSG[] = "undeclared qualifier: ";
 92            
 93            const char BadQualifierScope::MSG[] = "qualifier invalid in this scope: ";
 94            
 95            const char BadQualifierOverride::MSG[] = "qualifier not overridable: ";
 96            
 97 chip  1.39 const char BadQualifierType::MSG[] =
 98 mike  1.22     "CIMType of qualifier different than its declaration: ";
 99            
100            const char NullType::MSG[] = "type is null";
101            
102 chip  1.39 const char AddedReferenceToClass::MSG[] =
103 mike  1.22     "attempted to add reference to a non-association class: ";
104            
105 chip  1.39 const char ClassAlreadyResolved::MSG[] =
106 mike  1.22     "attempt to resolve a class that is already resolved: ";
107            
108 chip  1.39 const char ClassNotResolved::MSG[] =
109 mike  1.22     "class is not yet resolved: ";
110            
111 chip  1.39 const char InstanceAlreadyResolved::MSG[] =
112 mike  1.22     "attempted to resolve a instance that is already resolved";
113            
114 chip  1.39 const char InstantiatedAbstractClass::MSG[] =
115 karl  1.28     "attempted to instantiate an abstract class ";
116 mike  1.22 
117            const char NoSuchProperty::MSG[] = "no such property: ";
118            
119 chip  1.39 const char TruncatedCharacter::MSG[] =
120 mike  1.22     "truncated character during conversion from Char16 to char";
121            
122 chip  1.39 const char ExpectedReferenceValue::MSG[] =
123 kumpf 1.43     "Expected CIMValue object to be of type reference "
124 mike  1.22     "in this context";
125            
126            const char MissingReferenceClassName::MSG[] = "missing reference class name";
127            
128            const char IllegalTypeTag::MSG[] = "illegal type tag";
129            
130            const char TypeMismatch::MSG[] = "type mismatch";
131            
132 karl  1.25 const char CIMValueIsNull::MSG[] = "null CIMValue accessed";
133            
134            const char CIMValueInvalidType::MSG[] = "invalid CIMValue type";
135            
136 mike  1.24 const char DynamicCastFailed::MSG[] = "dynamic cast failed";
137            
138 mike  1.22 const char NoSuchFile::MSG[] = "no such file: ";
139            
140 mike  1.23 const char FileNotReadable::MSG[] = "file not readable: ";
141            
142 mike  1.22 const char CannotBindToAddress::MSG[] = "cannot bind to address: ";
143            
144            const char NoSuchDirectory::MSG[] = "no such directory: ";
145            
146            const char ChangeDirectoryFailed::MSG[] = "cannot change directory: ";
147            
148            const char CannotCreateDirectory::MSG[] = "cannot create directory: ";
149            
150            const char NoSuchNameSpace::MSG[] = "no such namespace: ";
151            
152            const char CannotOpenFile::MSG[] = "cannot open file: ";
153            
154            const char NotImplemented::MSG[] = "not implemented: ";
155            
156            const char CannotRemoveDirectory::MSG[] = "cannot remove directory: ";
157            
158            const char CannotRemoveFile::MSG[] = "cannot remove file: ";
159            
160            const char CannotRenameFile::MSG[] = "cannot rename file: ";
161            
162 mike  1.23 const char StackUnderflow::MSG[] = "stack underflow";
163            
164            const char StackOverflow::MSG[] = "stack overflow";
165 mike  1.22 
166            const char QueueUnderflow::MSG[] = "queue Underflow";
167            
168            const char BadFormat::MSG[] = "bad format passed to Formatter::format()";
169            
170            const char BadDateTimeFormat::MSG[] = "bad datetime format";
171            
172            const char IncompatibleTypes::MSG[] = "incompatible types";
173            
174            const char BadlyFormedCGIQueryString::MSG[] = "badly formed CGI query string";
175            
176            const char IllformedObjectName::MSG[] = "illformed object name: ";
177            
178            const char DynamicLoadFailed::MSG[] = "load of dynamic library failed: ";
179            
180 chip  1.39 const char DynamicLookupFailed::MSG[] =
181 mike  1.22     "lookup of symbol in dynamic library failed: ";
182            
183            const char CannotOpenDirectory::MSG[] = "cannot open directory: ";
184            
185            const char CorruptFile::MSG[] = "corrupt file: ";
186 mike  1.23 
187            const char BindFailed::MSG[] = "Bind failed: ";
188            
189            const char InvalidLocator::MSG[] = "Invalid locator: ";
190            
191            const char CannotCreateSocket::MSG[] = "Cannot create socket";
192            
193            const char CannotConnect::MSG[] = "Cannot connect to: ";
194            
195            const char UnexpectedFailure::MSG[] = "Unexpected failure";
196            
197            const char AlreadyConnected::MSG[] = "already connected";
198            
199            const char NotConnected::MSG[] = "not connected";
200            
201            const char TimedOut::MSG[] = "timed out";
202            
203            const char ParseError::MSG[] = "parse error: ";
204            
205            const char MissingNullTerminator::MSG[] = "missing null terminator: ";
206            
207 mike  1.23 const char SSL_Exception::MSG[] = "SSL Exception ";
208 mike  1.22 
209 kumpf 1.26 const char InvalidAuthHeader::MSG[] = "Invalid Authorization header";
210            
211 kumpf 1.40 const char UnauthorizedAccess::MSG[] = "Unauthorized access";
212            
213 kumpf 1.26 
214 mike  1.22 ////////////////////////////////////////////////////////////////////////////////
215            //
216            // CIMException
217            //
218            ////////////////////////////////////////////////////////////////////////////////
219            
220 kumpf 1.29 //
221 kumpf 1.37 // Creates a description without source file name and line number.
222 kumpf 1.29 //
223 kumpf 1.37 static String _makeCIMExceptionDescription(
224 kumpf 1.29     CIMStatusCode code,
225 kumpf 1.37     const String& message)
226 kumpf 1.29 {
227                String tmp;
228                tmp.append(CIMStatusCodeToString(code));
229 kumpf 1.41     if (message != String::EMPTY)
230                {
231                    tmp.append(": \"");
232                    tmp.append(message);
233                    tmp.append("\"");
234                }
235 kumpf 1.29     return tmp;
236            }
237            
238            //
239 kumpf 1.37 // Creates a description with source file name and line number.
240 kumpf 1.29 //
241 kumpf 1.37 static String _makeCIMExceptionDescription(
242 chip  1.39     CIMStatusCode code,
243 kumpf 1.37     const String& message,
244 mike  1.22     const char* file,
245 kumpf 1.31     Uint32 line)
246 mike  1.22 {
247                String tmp = file;
248                tmp.append("(");
249                char buffer[32];
250                sprintf(buffer, "%d", line);
251                tmp.append(buffer);
252                tmp.append("): ");
253 kumpf 1.41     tmp.append(_makeCIMExceptionDescription(code, message));
254 mike  1.22     return tmp;
255            }
256            
257            CIMException::CIMException(
258 chip  1.39     CIMStatusCode code,
259 kumpf 1.37     const String& message,
260 mike  1.22     const char* file,
261 kumpf 1.31     Uint32 line)
262 chip  1.39     :
263 kumpf 1.37     Exception(message),
264 kumpf 1.31     _code(code),
265                _file(file),
266                _line(line)
267 mike  1.22 {
268            
269 kumpf 1.32 }
270            
271 kumpf 1.37 //
272            // Returns a description string fit for human consumption
273            //
274            String CIMException::getDescription() const
275            {
276            #ifdef DEBUG_CIMEXCEPTION
277                return getTraceDescription();
278            #else
279                return _makeCIMExceptionDescription(_code, getMessage());
280            #endif
281            }
282            
283            //
284            // Returns a description string with filename and line number information
285 chip  1.39 // specifically for tracing.
286 kumpf 1.37 //
287            String CIMException::getTraceDescription() const
288            {
289                String traceDescription =
290                    _makeCIMExceptionDescription(_code, getMessage(), _file, _line);
291 chip  1.39 
292 kumpf 1.37     return traceDescription;
293 mike  1.22 }
294            
295 kumpf 1.38 void ThrowUninitializedHandle()
296 mike  1.22 {
297 kumpf 1.38     throw UninitializedHandle();
298 kumpf 1.45 }
299            
300            void ThrowUninitializedObject()
301            {
302                throw UninitializedObject();
303 mike  1.22 }
304            
305            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2