1 // VirtualDub - Video processing and capture application
2 // System library component
3 // Copyright (C) 1998-2012 Avery Lee, All Rights Reserved.
5 // Beginning with 1.6.0, the VirtualDub system library is licensed
6 // differently than the remainder of VirtualDub. This particular file is
7 // thus licensed as follows (the "zlib" license):
9 // This software is provided 'as-is', without any express or implied
10 // warranty. In no event will the authors be held liable for any
11 // damages arising from the use of this software.
13 // Permission is granted to anyone to use this software for any purpose,
14 // including commercial applications, and to alter it and redistribute it
15 // freely, subject to the following restrictions:
17 // 1. The origin of this software must not be misrepresented; you must
18 // not claim that you wrote the original software. If you use this
19 // software in a product, an acknowledgment in the product
20 // documentation would be appreciated but is not required.
21 // 2. Altered source versions must be plainly marked as such, and must
22 // not be misrepresented as being the original software.
23 // 3. This notice may not be removed or altered from any source
29 #include <vd2/system/Error.h>
31 /////////////////////////////////////////////////////////////////////////////
33 static const char *GetVCMErrorString(uint32 icErr
) {
34 const char *err
= "(unknown)";
36 // Does anyone have the *real* text strings for this?
39 case ICERR_OK
: err
= "The operation completed successfully."; break; // sorry, couldn't resist....
40 case ICERR_UNSUPPORTED
: err
= "The operation is not supported."; break;
41 case ICERR_BADFORMAT
: err
= "The source image format is not acceptable."; break;
42 case ICERR_MEMORY
: err
= "Not enough memory."; break;
43 case ICERR_INTERNAL
: err
= "An internal error occurred."; break;
44 case ICERR_BADFLAGS
: err
= "An invalid flag was specified."; break;
45 case ICERR_BADPARAM
: err
= "An invalid parameter was specified."; break;
46 case ICERR_BADSIZE
: err
= "An invalid size was specified."; break;
47 case ICERR_BADHANDLE
: err
= "The handle is invalid."; break;
48 case ICERR_CANTUPDATE
: err
= "Cannot update the destination image."; break;
49 case ICERR_ABORT
: err
= "The operation was aborted by the user."; break;
50 case ICERR_ERROR
: err
= "An unknown error occurred (may be corrupt data)."; break;
51 case ICERR_BADBITDEPTH
: err
= "The source color depth is not acceptable."; break;
52 case ICERR_BADIMAGESIZE
: err
= "The source image size is not acceptable."; break;
54 if (icErr
<= ICERR_CUSTOM
) err
= "A codec-specific error occurred.";
61 MyICError::MyICError(const char *s
, uint32 icErr
) {
62 setf("%s error: %s (error code %ld)", s
, GetVCMErrorString(icErr
), icErr
);
65 MyICError::MyICError(uint32 icErr
, const char *format
, ...) {
69 va_start(val
, format
);
70 tmpbuf
[(sizeof tmpbuf
) - 1] = 0;
71 _vsnprintf(tmpbuf
, (sizeof tmpbuf
) - 1, format
, val
);
74 setf(tmpbuf
, GetVCMErrorString(icErr
));
77 MyMMIOError::MyMMIOError(const char *s
, uint32 mmioerr
) {
78 const char *err
= "(Unknown)";
81 case MMIOERR_FILENOTFOUND
: err
= "file not found"; break;
82 case MMIOERR_OUTOFMEMORY
: err
= "out of memory"; break;
83 case MMIOERR_CANNOTOPEN
: err
= "couldn't open"; break;
84 case MMIOERR_CANNOTCLOSE
: err
= "couldn't close"; break;
85 case MMIOERR_CANNOTREAD
: err
= "couldn't read"; break;
86 case MMIOERR_CANNOTWRITE
: err
= "couldn't write"; break;
87 case MMIOERR_CANNOTSEEK
: err
= "couldn't seek"; break;
88 case MMIOERR_CANNOTEXPAND
: err
= "couldn't expand"; break;
89 case MMIOERR_CHUNKNOTFOUND
: err
= "chunk not found"; break;
90 case MMIOERR_UNBUFFERED
: err
= "unbuffered"; break;
91 case MMIOERR_PATHNOTFOUND
: err
= "path not found"; break;
92 case MMIOERR_ACCESSDENIED
: err
= "access denied"; break;
93 case MMIOERR_SHARINGVIOLATION
: err
= "sharing violation"; break;
94 case MMIOERR_NETWORKERROR
: err
= "network error"; break;
95 case MMIOERR_TOOMANYOPENFILES
: err
= "too many open files"; break;
96 case MMIOERR_INVALIDFILE
: err
= "invalid file"; break;
99 setf("%s error: %s (%ld)", s
, err
, mmioerr
);
102 MyAVIError::MyAVIError(const char *s
, uint32 avierr
) {
103 const char *err
= "(Unknown)";
106 case AVIERR_UNSUPPORTED
: err
= "unsupported"; break;
107 case AVIERR_BADFORMAT
: err
= "bad format"; break;
108 case AVIERR_MEMORY
: err
= "out of memory"; break;
109 case AVIERR_INTERNAL
: err
= "internal error"; break;
110 case AVIERR_BADFLAGS
: err
= "bad flags"; break;
111 case AVIERR_BADPARAM
: err
= "bad parameters"; break;
112 case AVIERR_BADSIZE
: err
= "bad size"; break;
113 case AVIERR_BADHANDLE
: err
= "bad AVIFile handle"; break;
114 case AVIERR_FILEREAD
: err
= "file read error"; break;
115 case AVIERR_FILEWRITE
: err
= "file write error"; break;
116 case AVIERR_FILEOPEN
: err
= "file open error"; break;
117 case AVIERR_COMPRESSOR
: err
= "compressor error"; break;
118 case AVIERR_NOCOMPRESSOR
: err
= "compressor not available"; break;
119 case AVIERR_READONLY
: err
= "file marked read-only"; break;
120 case AVIERR_NODATA
: err
= "no data (?)"; break;
121 case AVIERR_BUFFERTOOSMALL
: err
= "buffer too small"; break;
122 case AVIERR_CANTCOMPRESS
: err
= "can't compress (?)"; break;
123 case AVIERR_USERABORT
: err
= "aborted by user"; break;
124 case AVIERR_ERROR
: err
= "error (?)"; break;
127 setf("%s error: %s (%08lx)", s
, err
, avierr
);
130 MyWin32Error::MyWin32Error(const char *format
, uint32 err
, ...)
138 szError
[(sizeof szError
)-1] = 0;
139 _vsnprintf(szError
, (sizeof szError
)-1, format
, val
);
142 // Determine the position of the last %s, and escape everything else. This doesn't
143 // track escaped % signs properly, but it works for the strings that we receive (and at
144 // worst just produces a funny message).
145 const char *keep
= strstr(szError
, "%s");
148 const char *test
= strstr(keep
+ 1, "%s");
158 char *end
= szTemp
+ (sizeof szTemp
) - 1;
159 const char *s
= szError
;
161 while(char c
= *s
++) {
163 // We allow one %s to go through. Everything else gets escaped.
180 if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
,
183 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
192 long l
= strlen(szError
);
194 if (l
>1 && szError
[l
-2] == '\r')
196 else if (szError
[l
-1] == '\n')
200 setf(szTemp
, szError
);
203 MyCrashError::MyCrashError(const char *format
, uint32 dwExceptionCode
) {
204 const char *s
= "(Unknown Exception)";
206 switch(dwExceptionCode
) {
207 case EXCEPTION_ACCESS_VIOLATION
:
208 s
= "Access Violation";
210 case EXCEPTION_PRIV_INSTRUCTION
:
211 s
= "Privileged Instruction";
213 case EXCEPTION_INT_DIVIDE_BY_ZERO
:
214 s
= "Integer Divide By Zero";
216 case EXCEPTION_BREAKPOINT
:
217 s
= "User Breakpoint";