~ubuntu-branches/ubuntu/intrepid/graphicsmagick/intrepid

« back to all changes in this revision

Viewing changes to Magick++/lib/Exception.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2006-05-06 16:28:08 UTC
  • Revision ID: james.westby@ubuntu.com-20060506162808-vt2ni3r5nytcszms
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This may look like C code, but it is really -*- C++ -*-
 
2
//
 
3
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
 
4
//
 
5
// Implementation of Exception and derived classes
 
6
//
 
7
 
 
8
#define MAGICK_IMPLEMENTATION
 
9
 
 
10
#include "Magick++/Include.h"
 
11
#include <string>
 
12
#include <errno.h>
 
13
#include <string.h>
 
14
 
 
15
using namespace std;
 
16
 
 
17
#include "Magick++/Exception.h"
 
18
 
 
19
// Construct with message string
 
20
Magick::Exception::Exception( const std::string& what_ )
 
21
  : _what(what_)
 
22
{
 
23
}
 
24
 
 
25
// Copy constructor
 
26
Magick::Exception::Exception( const Magick::Exception& original_ )
 
27
  : _what(original_._what)
 
28
{
 
29
}
 
30
 
 
31
// Assignment operator
 
32
Magick::Exception& Magick::Exception::operator= (const Magick::Exception& original_ )
 
33
{
 
34
  if(this != &original_)
 
35
    {
 
36
      this->_what = original_._what;
 
37
    }
 
38
  return *this;
 
39
}
 
40
 
 
41
// Return message string
 
42
/*virtual*/ const char* Magick::Exception::what( ) const throw()
 
43
{
 
44
  return _what.c_str();
 
45
}
 
46
 
 
47
/* Destructor */
 
48
/*virtual*/ Magick::Exception::~Exception ( ) throw ()
 
49
{
 
50
}
 
51
 
 
52
//
 
53
// Warnings
 
54
//
 
55
 
 
56
Magick::Warning::Warning ( const std::string& what_ )
 
57
  : Exception(what_)
 
58
{
 
59
}
 
60
 
 
61
Magick::WarningUndefined::WarningUndefined ( const std::string& what_ )
 
62
  : Warning(what_)
 
63
{
 
64
}
 
65
 
 
66
Magick::WarningBlob::WarningBlob ( const std::string& what_ )
 
67
  : Warning(what_)
 
68
{
 
69
}
 
70
 
 
71
Magick::WarningCache::WarningCache ( const std::string& what_ )
 
72
  : Warning(what_)
 
73
{
 
74
}
 
75
 
 
76
Magick::WarningCoder::WarningCoder ( const std::string& what_ )
 
77
  : Warning(what_)
 
78
{
 
79
}
 
80
 
 
81
Magick::WarningConfigure::WarningConfigure ( const std::string& what_ )
 
82
  : Warning(what_)
 
83
{
 
84
}
 
85
 
 
86
Magick::WarningCorruptImage::WarningCorruptImage ( const std::string& what_ )
 
87
  : Warning(what_)
 
88
{
 
89
}
 
90
 
 
91
Magick::WarningDelegate::WarningDelegate ( const std::string& what_ )
 
92
  : Warning(what_)
 
93
{
 
94
}
 
95
 
 
96
Magick::WarningDraw::WarningDraw ( const std::string& what_ )
 
97
  : Warning(what_)
 
98
{
 
99
}
 
100
 
 
101
Magick::WarningFileOpen::WarningFileOpen ( const std::string& what_ )
 
102
  : Warning(what_)
 
103
{
 
104
}
 
105
 
 
106
Magick::WarningImage::WarningImage ( const std::string& what_ )
 
107
  : Warning(what_)
 
108
{
 
109
}
 
110
 
 
111
Magick::WarningMissingDelegate::WarningMissingDelegate ( const std::string& what_ )
 
112
  : Warning(what_)
 
113
{
 
114
}
 
115
 
 
116
Magick::WarningModule::WarningModule ( const std::string& what_ )
 
117
  : Warning(what_)
 
118
{
 
119
}
 
120
 
 
121
Magick::WarningMonitor::WarningMonitor ( const std::string& what_ )
 
122
  : Warning(what_)
 
123
{
 
124
}
 
125
 
 
126
Magick::WarningOption::WarningOption ( const std::string& what_ )
 
127
  : Warning(what_)
 
128
{
 
129
}
 
130
 
 
131
Magick::WarningRegistry::WarningRegistry ( const std::string& what_ )
 
132
  : Warning(what_)
 
133
{
 
134
}
 
135
 
 
136
Magick::WarningResourceLimit::WarningResourceLimit ( const std::string& what_ )
 
137
  : Warning(what_)
 
138
{
 
139
}
 
140
 
 
141
Magick::WarningStream::WarningStream ( const std::string& what_ )
 
142
  : Warning(what_)
 
143
{
 
144
}
 
145
 
 
146
Magick::WarningType::WarningType ( const std::string& what_ )
 
147
  : Warning(what_)
 
148
{
 
149
}
 
150
 
 
151
Magick::WarningXServer::WarningXServer ( const std::string& what_ )
 
152
  : Warning(what_)
 
153
{
 
154
}
 
155
 
 
156
//
 
157
// Errors
 
158
//
 
159
 
 
160
Magick::Error::Error ( const std::string& what_ )
 
161
  : Exception(what_)
 
162
{
 
163
}
 
164
 
 
165
Magick::ErrorUndefined::ErrorUndefined ( const std::string& what_ )
 
166
  : Error(what_)
 
167
{
 
168
}
 
169
 
 
170
Magick::ErrorBlob::ErrorBlob ( const std::string& what_ )
 
171
  : Error(what_)
 
172
{
 
173
}
 
174
 
 
175
Magick::ErrorCache::ErrorCache ( const std::string& what_ )
 
176
  : Error(what_)
 
177
{
 
178
}
 
179
 
 
180
Magick::ErrorCoder::ErrorCoder ( const std::string& what_ )
 
181
  : Error(what_)
 
182
{
 
183
}
 
184
 
 
185
Magick::ErrorConfigure::ErrorConfigure ( const std::string& what_ )
 
186
  : Error(what_)
 
187
{
 
188
}
 
189
 
 
190
Magick::ErrorCorruptImage::ErrorCorruptImage ( const std::string& what_ )
 
191
  : Error(what_)
 
192
{
 
193
}
 
194
 
 
195
Magick::ErrorDelegate::ErrorDelegate ( const std::string& what_ )
 
196
  : Error(what_)
 
197
{
 
198
}
 
199
 
 
200
Magick::ErrorDraw::ErrorDraw ( const std::string& what_ )
 
201
  : Error(what_)
 
202
{
 
203
}
 
204
 
 
205
Magick::ErrorFileOpen::ErrorFileOpen ( const std::string& what_ )
 
206
  : Error(what_)
 
207
{
 
208
}
 
209
 
 
210
Magick::ErrorImage::ErrorImage ( const std::string& what_ )
 
211
  : Error(what_)
 
212
{
 
213
}
 
214
 
 
215
Magick::ErrorMissingDelegate::ErrorMissingDelegate ( const std::string& what_ )
 
216
  : Error(what_)
 
217
{
 
218
}
 
219
 
 
220
Magick::ErrorModule::ErrorModule ( const std::string& what_ )
 
221
  : Error(what_)
 
222
{
 
223
}
 
224
 
 
225
Magick::ErrorMonitor::ErrorMonitor ( const std::string& what_ )
 
226
  : Error(what_)
 
227
{
 
228
}
 
229
 
 
230
Magick::ErrorOption::ErrorOption ( const std::string& what_ )
 
231
  : Error(what_)
 
232
{
 
233
}
 
234
 
 
235
Magick::ErrorRegistry::ErrorRegistry ( const std::string& what_ )
 
236
  : Error(what_)
 
237
{
 
238
}
 
239
 
 
240
Magick::ErrorResourceLimit::ErrorResourceLimit ( const std::string& what_ )
 
241
  : Error(what_)
 
242
{
 
243
}
 
244
 
 
245
Magick::ErrorStream::ErrorStream ( const std::string& what_ )
 
246
  : Error(what_)
 
247
{
 
248
}
 
249
 
 
250
Magick::ErrorType::ErrorType ( const std::string& what_ )
 
251
  : Error(what_)
 
252
{
 
253
}
 
254
 
 
255
Magick::ErrorXServer::ErrorXServer ( const std::string& what_ )
 
256
  : Error(what_)
 
257
{
 
258
}
 
259
 
 
260
// Format and throw exception
 
261
MagickDLLDecl void Magick::throwExceptionExplicit( const ExceptionType severity_,
 
262
                                                   const char* reason_,
 
263
                                                   const char* description_)
 
264
{
 
265
  // Just return if there is no reported error
 
266
  if ( severity_ == UndefinedException )
 
267
    return;
 
268
 
 
269
  ExceptionInfo exception;
 
270
 
 
271
  GetExceptionInfo( &exception );
 
272
  ThrowException2( &exception, severity_, reason_, description_ );
 
273
  throwException( exception );
 
274
}
 
275
 
 
276
// Throw C++ exception, resetting exception argument to default state
 
277
MagickDLLDecl void Magick::throwException( ExceptionInfo &exception_ )
 
278
{
 
279
  // Just return if there is no reported error
 
280
  if ( exception_.severity == UndefinedException )
 
281
    return;
 
282
 
 
283
  // Format error message GraphicsMagick-style
 
284
  std::string message = SetClientName(0);
 
285
  if ( exception_.reason != 0 )
 
286
    {
 
287
      message += std::string(": ");
 
288
      message += std::string(exception_.reason);
 
289
    }
 
290
 
 
291
  if ( exception_.description != 0 )
 
292
    message += " (" + std::string(exception_.description) + ")";
 
293
 
 
294
  if ( exception_.module != 0)
 
295
    {
 
296
      char line_str[24];
 
297
      sprintf( line_str, "%lu", exception_.line);
 
298
      message += " reported by " + std::string(exception_.module);
 
299
      message += ":" + std::string(line_str);
 
300
      if ((exception_.function != 0) && strcmp("unknown",exception_.function))
 
301
          message += " (" + std::string(exception_.function) + ")";
 
302
    }
 
303
 
 
304
  ExceptionType severity = exception_.severity;
 
305
  DestroyExceptionInfo( &exception_ );
 
306
  GetExceptionInfo( &exception_ );
 
307
 
 
308
  switch ( severity )
 
309
    {
 
310
      // Warnings
 
311
    case ResourceLimitWarning :
 
312
      throw WarningResourceLimit( message );
 
313
    case TypeWarning :
 
314
      throw WarningType( message );
 
315
    case OptionWarning :
 
316
      throw WarningOption( message );
 
317
    case DelegateWarning :
 
318
      throw WarningDelegate( message );
 
319
    case MissingDelegateWarning :
 
320
      throw WarningMissingDelegate( message );
 
321
    case CorruptImageWarning :
 
322
      throw WarningCorruptImage( message );
 
323
    case FileOpenWarning :
 
324
      throw WarningFileOpen( message );
 
325
    case BlobWarning :
 
326
      throw WarningBlob ( message );
 
327
    case StreamWarning :
 
328
      throw WarningStream ( message );
 
329
    case CacheWarning :
 
330
      throw WarningCache ( message );
 
331
    case CoderWarning :
 
332
      throw WarningCoder ( message );
 
333
    case ModuleWarning :
 
334
      throw WarningModule( message );
 
335
    case DrawWarning :
 
336
      throw WarningDraw( message );
 
337
    case ImageWarning :
 
338
      throw WarningImage( message );
 
339
    case XServerWarning :
 
340
      throw WarningXServer( message );
 
341
    case MonitorWarning :
 
342
      throw WarningMonitor( message );
 
343
    case RegistryWarning :
 
344
      throw WarningRegistry( message );
 
345
    case ConfigureWarning :
 
346
      throw WarningConfigure( message );
 
347
      // Errors
 
348
    case ResourceLimitError :
 
349
    case ResourceLimitFatalError :
 
350
      throw ErrorResourceLimit( message );
 
351
    case TypeError :
 
352
    case TypeFatalError :
 
353
      throw ErrorType( message );
 
354
    case OptionError :
 
355
    case OptionFatalError :
 
356
      throw ErrorOption( message );
 
357
    case DelegateError :
 
358
    case DelegateFatalError :
 
359
      throw ErrorDelegate( message );
 
360
    case MissingDelegateError :
 
361
    case MissingDelegateFatalError :
 
362
      throw ErrorMissingDelegate( message );
 
363
    case CorruptImageError :
 
364
    case CorruptImageFatalError :
 
365
      throw ErrorCorruptImage( message );
 
366
    case FileOpenError :
 
367
    case FileOpenFatalError :
 
368
      throw ErrorFileOpen( message );
 
369
    case BlobError :
 
370
    case BlobFatalError :
 
371
      throw ErrorBlob ( message );
 
372
    case StreamError :
 
373
    case StreamFatalError :
 
374
      throw ErrorStream ( message );
 
375
    case CacheError :
 
376
    case CacheFatalError :
 
377
      throw ErrorCache ( message );
 
378
    case CoderError :
 
379
    case CoderFatalError :
 
380
      throw ErrorCoder ( message );
 
381
    case ModuleError :
 
382
    case ModuleFatalError :
 
383
      throw ErrorModule ( message );
 
384
    case DrawError :
 
385
    case DrawFatalError :
 
386
      throw ErrorDraw ( message );
 
387
    case ImageError :
 
388
    case ImageFatalError :
 
389
      throw ErrorImage ( message );
 
390
    case XServerError :
 
391
    case XServerFatalError :
 
392
      throw ErrorXServer ( message );
 
393
    case MonitorError :
 
394
    case MonitorFatalError :
 
395
      throw ErrorMonitor ( message );
 
396
    case RegistryError :
 
397
    case RegistryFatalError :
 
398
      throw ErrorRegistry ( message );
 
399
    case ConfigureError :
 
400
    case ConfigureFatalError :
 
401
      throw ErrorConfigure ( message );
 
402
    case UndefinedException :
 
403
    default :
 
404
      throw ErrorUndefined( message );
 
405
    }
 
406
 
 
407
}