1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
7 // ---------------------------------------------------------------------------
9 // ---------------------------------------------------------------------------
19 #include "../dlls/mscorrc/resource.h"
25 #define MAX_EXCEPTION_MSG 200
27 // Set if fatal error (like stack overflow or out of memory) occurred in this process.
28 GVAL_IMPL_INIT(HRESULT, g_hrFatalError, S_OK);
30 // Helper function to get an exception object from outside the exception. In
31 // the CLR, it may be from the Thread object. Non-CLR users have no thread object,
32 // and it will do nothing.
33 void GetLastThrownObjectExceptionFromThread(void **ppvException);
35 Exception *Exception::g_OOMException = NULL;
37 // avoid global constructors
38 static BYTE g_OOMExceptionInstance[sizeof(OutOfMemoryException)];
40 Exception * Exception::GetOOMException()
42 LIMITED_METHOD_CONTRACT;
44 if (!g_OOMException) {
45 // Create a local copy on the stack and then copy it over to the static instance.
46 // This avoids race conditions caused by multiple initializations of vtable in the constructor
48 OutOfMemoryException local(TRUE); // Construct a "preallocated" instance.
49 memcpy((void*)&g_OOMExceptionInstance, (void*)&local, sizeof(OutOfMemoryException));
51 g_OOMException = (OutOfMemoryException*)&g_OOMExceptionInstance;
54 return g_OOMException;
57 /*virtual*/ Exception *OutOfMemoryException::Clone()
59 LIMITED_METHOD_CONTRACT;
61 return GetOOMException();
64 //------------------------------------------------------------------------------
65 void Exception::Delete(Exception* pvMemory)
71 SUPPORTS_DAC_HOST_ONLY; // Exceptions aren't currently marshalled by DAC - just used in the host
75 if ((pvMemory == 0) || pvMemory->IsPreallocatedException())
80 ::delete((Exception *) pvMemory);
83 void Exception::GetMessage(SString &result)
87 return GenerateTopLevelHRExceptionMessage(GetHR(), result);
90 void HRMsgException::GetMessage(SString &result)
95 HRException::GetMessage(result);
100 Exception *Exception::Clone()
109 NewHolder<Exception> retExcep(CloneHelper());
110 if (m_innerException)
112 retExcep->m_innerException = m_innerException->Clone();
115 retExcep.SuppressRelease();
119 Exception *Exception::CloneHelper()
123 return new HRMsgException(GetHR(), s);
126 Exception *Exception::DomainBoundClone()
130 // Because we may call DomainBoundCloneHelper() of ObjrefException or CLRLastThrownObjectException
131 // this should be GC_TRIGGERS, but we can not include EE contracts in Utilcode.
136 NewHolder<Exception> retExcep(DomainBoundCloneHelper());
137 if (m_innerException)
139 retExcep->m_innerException = m_innerException->DomainBoundClone();
142 retExcep.SuppressRelease();
146 BOOL Exception::IsTerminal()
153 // CLRException::GetHR() can eventually call BaseDomain::CreateHandle(),
154 // which can indirectly cause a lock if we get a miss in the handle table
155 // cache (TableCacheMissOnAlloc). Since CLRException::GetHR() is virtual,
156 // SCAN won't find this for you (though 40 minutes of one of the sql stress
162 HRESULT hr = GetHR();
163 return (COR_E_THREADABORTED == hr);
166 BOOL Exception::IsTransient()
170 return IsTransient(GetHR());
174 BOOL Exception::IsTransient(HRESULT hr)
176 LIMITED_METHOD_CONTRACT;
178 return (hr == COR_E_THREADABORTED
179 || hr == COR_E_THREADINTERRUPTED
180 || hr == COR_E_THREADSTOP
181 || hr == COR_E_APPDOMAINUNLOADED
182 || hr == E_OUTOFMEMORY
183 || hr == HRESULT_FROM_WIN32(ERROR_COMMITMENT_LIMIT) // ran out of room in pagefile
184 || hr == HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY)
185 || hr == (HRESULT)STATUS_NO_MEMORY
186 || hr == COR_E_STACKOVERFLOW
187 || hr == MSEE_E_ASSEMBLYLOADINPROGRESS);
190 //------------------------------------------------------------------------------
191 // Functions to manage the preallocated exceptions.
193 BOOL Exception::IsPreallocatedException()
194 { // Most exceptions can't be preallocated. If they can be, their class
195 // should provide a virtual override of this function.
199 BOOL Exception::IsPreallocatedOOMException()
200 { // This is the preallocated OOM if it is preallocated and is OOM.
201 return IsPreallocatedException() && (GetInstanceType() == OutOfMemoryException::GetType());
204 //------------------------------------------------------------------------------
206 #pragma warning(push)
207 #pragma warning(disable:21000) // Suppress PREFast warning about overly large function
209 LPCSTR Exception::GetHRSymbolicName(HRESULT hr)
211 LIMITED_METHOD_CONTRACT;
213 #define CASE_HRESULT(hrname) case hrname: return #hrname;
217 CASE_HRESULT(S_OK)// 0x00000000L
218 CASE_HRESULT(S_FALSE)// 0x00000001L
220 CASE_HRESULT(E_UNEXPECTED)// 0x8000FFFFL
221 CASE_HRESULT(E_NOTIMPL)// 0x80004001L
222 CASE_HRESULT(E_OUTOFMEMORY)// 0x8007000EL
223 CASE_HRESULT(E_INVALIDARG)// 0x80070057L
224 CASE_HRESULT(E_NOINTERFACE)// 0x80004002L
225 CASE_HRESULT(E_POINTER)// 0x80004003L
226 CASE_HRESULT(E_HANDLE)// 0x80070006L
227 CASE_HRESULT(E_ABORT)// 0x80004004L
228 CASE_HRESULT(E_FAIL)// 0x80004005L
229 CASE_HRESULT(E_ACCESSDENIED)// 0x80070005L
231 #ifdef FEATURE_COMINTEROP
232 CASE_HRESULT(CO_E_INIT_TLS)// 0x80004006L
233 CASE_HRESULT(CO_E_INIT_SHARED_ALLOCATOR)// 0x80004007L
234 CASE_HRESULT(CO_E_INIT_MEMORY_ALLOCATOR)// 0x80004008L
235 CASE_HRESULT(CO_E_INIT_CLASS_CACHE)// 0x80004009L
236 CASE_HRESULT(CO_E_INIT_RPC_CHANNEL)// 0x8000400AL
237 CASE_HRESULT(CO_E_INIT_TLS_SET_CHANNEL_CONTROL)// 0x8000400BL
238 CASE_HRESULT(CO_E_INIT_TLS_CHANNEL_CONTROL)// 0x8000400CL
239 CASE_HRESULT(CO_E_INIT_UNACCEPTED_USER_ALLOCATOR)// 0x8000400DL
240 CASE_HRESULT(CO_E_INIT_SCM_MUTEX_EXISTS)// 0x8000400EL
241 CASE_HRESULT(CO_E_INIT_SCM_FILE_MAPPING_EXISTS)// 0x8000400FL
242 CASE_HRESULT(CO_E_INIT_SCM_MAP_VIEW_OF_FILE)// 0x80004010L
243 CASE_HRESULT(CO_E_INIT_SCM_EXEC_FAILURE)// 0x80004011L
244 CASE_HRESULT(CO_E_INIT_ONLY_SINGLE_THREADED)// 0x80004012L
246 // ******************
248 // ******************
250 CASE_HRESULT(OLE_E_OLEVERB)// 0x80040000L
251 CASE_HRESULT(OLE_E_ADVF)// 0x80040001L
252 CASE_HRESULT(OLE_E_ENUM_NOMORE)// 0x80040002L
253 CASE_HRESULT(OLE_E_ADVISENOTSUPPORTED)// 0x80040003L
254 CASE_HRESULT(OLE_E_NOCONNECTION)// 0x80040004L
255 CASE_HRESULT(OLE_E_NOTRUNNING)// 0x80040005L
256 CASE_HRESULT(OLE_E_NOCACHE)// 0x80040006L
257 CASE_HRESULT(OLE_E_BLANK)// 0x80040007L
258 CASE_HRESULT(OLE_E_CLASSDIFF)// 0x80040008L
259 CASE_HRESULT(OLE_E_CANT_GETMONIKER)// 0x80040009L
260 CASE_HRESULT(OLE_E_CANT_BINDTOSOURCE)// 0x8004000AL
261 CASE_HRESULT(OLE_E_STATIC)// 0x8004000BL
262 CASE_HRESULT(OLE_E_PROMPTSAVECANCELLED)// 0x8004000CL
263 CASE_HRESULT(OLE_E_INVALIDRECT)// 0x8004000DL
264 CASE_HRESULT(OLE_E_WRONGCOMPOBJ)// 0x8004000EL
265 CASE_HRESULT(OLE_E_INVALIDHWND)// 0x8004000FL
266 CASE_HRESULT(OLE_E_NOT_INPLACEACTIVE)// 0x80040010L
267 CASE_HRESULT(OLE_E_CANTCONVERT)// 0x80040011L
268 CASE_HRESULT(OLE_E_NOSTORAGE)// 0x80040012L
269 CASE_HRESULT(DV_E_FORMATETC)// 0x80040064L
270 CASE_HRESULT(DV_E_DVTARGETDEVICE)// 0x80040065L
271 CASE_HRESULT(DV_E_STGMEDIUM)// 0x80040066L
272 CASE_HRESULT(DV_E_STATDATA)// 0x80040067L
273 CASE_HRESULT(DV_E_LINDEX)// 0x80040068L
274 CASE_HRESULT(DV_E_TYMED)// 0x80040069L
275 CASE_HRESULT(DV_E_CLIPFORMAT)// 0x8004006AL
276 CASE_HRESULT(DV_E_DVASPECT)// 0x8004006BL
277 CASE_HRESULT(DV_E_DVTARGETDEVICE_SIZE)// 0x8004006CL
278 CASE_HRESULT(DV_E_NOIVIEWOBJECT)// 0x8004006DL
279 CASE_HRESULT(DRAGDROP_E_NOTREGISTERED)// 0x80040100L
280 CASE_HRESULT(DRAGDROP_E_ALREADYREGISTERED)// 0x80040101L
281 CASE_HRESULT(DRAGDROP_E_INVALIDHWND)// 0x80040102L
282 CASE_HRESULT(CLASS_E_NOAGGREGATION)// 0x80040110L
283 CASE_HRESULT(CLASS_E_CLASSNOTAVAILABLE)// 0x80040111L
284 CASE_HRESULT(VIEW_E_DRAW)// 0x80040140L
285 CASE_HRESULT(REGDB_E_READREGDB)// 0x80040150L
286 CASE_HRESULT(REGDB_E_WRITEREGDB)// 0x80040151L
287 CASE_HRESULT(REGDB_E_KEYMISSING)// 0x80040152L
288 CASE_HRESULT(REGDB_E_INVALIDVALUE)// 0x80040153L
289 CASE_HRESULT(REGDB_E_CLASSNOTREG)// 0x80040154L
290 CASE_HRESULT(CACHE_E_NOCACHE_UPDATED)// 0x80040170L
291 CASE_HRESULT(OLEOBJ_E_NOVERBS)// 0x80040180L
292 CASE_HRESULT(INPLACE_E_NOTUNDOABLE)// 0x800401A0L
293 CASE_HRESULT(INPLACE_E_NOTOOLSPACE)// 0x800401A1L
294 CASE_HRESULT(CONVERT10_E_OLESTREAM_GET)// 0x800401C0L
295 CASE_HRESULT(CONVERT10_E_OLESTREAM_PUT)// 0x800401C1L
296 CASE_HRESULT(CONVERT10_E_OLESTREAM_FMT)// 0x800401C2L
297 CASE_HRESULT(CONVERT10_E_OLESTREAM_BITMAP_TO_DIB)// 0x800401C3L
298 CASE_HRESULT(CONVERT10_E_STG_FMT)// 0x800401C4L
299 CASE_HRESULT(CONVERT10_E_STG_NO_STD_STREAM)// 0x800401C5L
300 CASE_HRESULT(CONVERT10_E_STG_DIB_TO_BITMAP)// 0x800401C6L
301 CASE_HRESULT(CLIPBRD_E_CANT_OPEN)// 0x800401D0L
302 CASE_HRESULT(CLIPBRD_E_CANT_EMPTY)// 0x800401D1L
303 CASE_HRESULT(CLIPBRD_E_CANT_SET)// 0x800401D2L
304 CASE_HRESULT(CLIPBRD_E_BAD_DATA)// 0x800401D3L
305 CASE_HRESULT(CLIPBRD_E_CANT_CLOSE)// 0x800401D4L
306 CASE_HRESULT(MK_E_CONNECTMANUALLY)// 0x800401E0L
307 CASE_HRESULT(MK_E_EXCEEDEDDEADLINE)// 0x800401E1L
308 CASE_HRESULT(MK_E_NEEDGENERIC)// 0x800401E2L
309 CASE_HRESULT(MK_E_UNAVAILABLE)// 0x800401E3L
310 CASE_HRESULT(MK_E_SYNTAX)// 0x800401E4L
311 CASE_HRESULT(MK_E_NOOBJECT)// 0x800401E5L
312 CASE_HRESULT(MK_E_INVALIDEXTENSION)// 0x800401E6L
313 CASE_HRESULT(MK_E_INTERMEDIATEINTERFACENOTSUPPORTED)// 0x800401E7L
314 CASE_HRESULT(MK_E_NOTBINDABLE)// 0x800401E8L
315 CASE_HRESULT(MK_E_NOTBOUND)// 0x800401E9L
316 CASE_HRESULT(MK_E_CANTOPENFILE)// 0x800401EAL
317 CASE_HRESULT(MK_E_MUSTBOTHERUSER)// 0x800401EBL
318 CASE_HRESULT(MK_E_NOINVERSE)// 0x800401ECL
319 CASE_HRESULT(MK_E_NOSTORAGE)// 0x800401EDL
320 CASE_HRESULT(MK_E_NOPREFIX)// 0x800401EEL
321 CASE_HRESULT(MK_E_ENUMERATION_FAILED)// 0x800401EFL
322 CASE_HRESULT(CO_E_NOTINITIALIZED)// 0x800401F0L
323 CASE_HRESULT(CO_E_ALREADYINITIALIZED)// 0x800401F1L
324 CASE_HRESULT(CO_E_CANTDETERMINECLASS)// 0x800401F2L
325 CASE_HRESULT(CO_E_CLASSSTRING)// 0x800401F3L
326 CASE_HRESULT(CO_E_IIDSTRING)// 0x800401F4L
327 CASE_HRESULT(CO_E_APPNOTFOUND)// 0x800401F5L
328 CASE_HRESULT(CO_E_APPSINGLEUSE)// 0x800401F6L
329 CASE_HRESULT(CO_E_ERRORINAPP)// 0x800401F7L
330 CASE_HRESULT(CO_E_DLLNOTFOUND)// 0x800401F8L
331 CASE_HRESULT(CO_E_ERRORINDLL)// 0x800401F9L
332 CASE_HRESULT(CO_E_WRONGOSFORAPP)// 0x800401FAL
333 CASE_HRESULT(CO_E_OBJNOTREG)// 0x800401FBL
334 CASE_HRESULT(CO_E_OBJISREG)// 0x800401FCL
335 CASE_HRESULT(CO_E_OBJNOTCONNECTED)// 0x800401FDL
336 CASE_HRESULT(CO_E_APPDIDNTREG)// 0x800401FEL
337 CASE_HRESULT(CO_E_RELEASED)// 0x800401FFL
339 CASE_HRESULT(OLE_S_USEREG)// 0x00040000L
340 CASE_HRESULT(OLE_S_STATIC)// 0x00040001L
341 CASE_HRESULT(OLE_S_MAC_CLIPFORMAT)// 0x00040002L
342 CASE_HRESULT(DRAGDROP_S_DROP)// 0x00040100L
343 CASE_HRESULT(DRAGDROP_S_CANCEL)// 0x00040101L
344 CASE_HRESULT(DRAGDROP_S_USEDEFAULTCURSORS)// 0x00040102L
345 CASE_HRESULT(DATA_S_SAMEFORMATETC)// 0x00040130L
346 CASE_HRESULT(VIEW_S_ALREADY_FROZEN)// 0x00040140L
347 CASE_HRESULT(CACHE_S_FORMATETC_NOTSUPPORTED)// 0x00040170L
348 CASE_HRESULT(CACHE_S_SAMECACHE)// 0x00040171L
349 CASE_HRESULT(CACHE_S_SOMECACHES_NOTUPDATED)// 0x00040172L
350 CASE_HRESULT(OLEOBJ_S_INVALIDVERB)// 0x00040180L
351 CASE_HRESULT(OLEOBJ_S_CANNOT_DOVERB_NOW)// 0x00040181L
352 CASE_HRESULT(OLEOBJ_S_INVALIDHWND)// 0x00040182L
353 CASE_HRESULT(INPLACE_S_TRUNCATED)// 0x000401A0L
354 CASE_HRESULT(CONVERT10_S_NO_PRESENTATION)// 0x000401C0L
355 CASE_HRESULT(MK_S_REDUCED_TO_SELF)// 0x000401E2L
356 CASE_HRESULT(MK_S_ME)// 0x000401E4L
357 CASE_HRESULT(MK_S_HIM)// 0x000401E5L
358 CASE_HRESULT(MK_S_US)// 0x000401E6L
359 CASE_HRESULT(MK_S_MONIKERALREADYREGISTERED)// 0x000401E7L
361 // ******************
363 // ******************
365 CASE_HRESULT(CO_E_CLASS_CREATE_FAILED)// 0x80080001L
366 CASE_HRESULT(CO_E_SCM_ERROR)// 0x80080002L
367 CASE_HRESULT(CO_E_SCM_RPC_FAILURE)// 0x80080003L
368 CASE_HRESULT(CO_E_BAD_PATH)// 0x80080004L
369 CASE_HRESULT(CO_E_SERVER_EXEC_FAILURE)// 0x80080005L
370 CASE_HRESULT(CO_E_OBJSRV_RPC_FAILURE)// 0x80080006L
371 CASE_HRESULT(MK_E_NO_NORMALIZED)// 0x80080007L
372 CASE_HRESULT(CO_E_SERVER_STOPPING)// 0x80080008L
373 CASE_HRESULT(MEM_E_INVALID_ROOT)// 0x80080009L
374 CASE_HRESULT(MEM_E_INVALID_LINK)// 0x80080010L
375 CASE_HRESULT(MEM_E_INVALID_SIZE)// 0x80080011L
377 // ******************
379 // ******************
381 CASE_HRESULT(DISP_E_UNKNOWNINTERFACE)// 0x80020001L
382 CASE_HRESULT(DISP_E_MEMBERNOTFOUND)// 0x80020003L
383 CASE_HRESULT(DISP_E_PARAMNOTFOUND)// 0x80020004L
384 CASE_HRESULT(DISP_E_TYPEMISMATCH)// 0x80020005L
385 CASE_HRESULT(DISP_E_UNKNOWNNAME)// 0x80020006L
386 CASE_HRESULT(DISP_E_NONAMEDARGS)// 0x80020007L
387 CASE_HRESULT(DISP_E_BADVARTYPE)// 0x80020008L
388 CASE_HRESULT(DISP_E_EXCEPTION)// 0x80020009L
389 CASE_HRESULT(DISP_E_OVERFLOW)// 0x8002000AL
390 CASE_HRESULT(DISP_E_BADINDEX)// 0x8002000BL
391 CASE_HRESULT(DISP_E_UNKNOWNLCID)// 0x8002000CL
392 CASE_HRESULT(DISP_E_ARRAYISLOCKED)// 0x8002000DL
393 CASE_HRESULT(DISP_E_BADPARAMCOUNT)// 0x8002000EL
394 CASE_HRESULT(DISP_E_PARAMNOTOPTIONAL)// 0x8002000FL
395 CASE_HRESULT(DISP_E_BADCALLEE)// 0x80020010L
396 CASE_HRESULT(DISP_E_NOTACOLLECTION)// 0x80020011L
397 CASE_HRESULT(TYPE_E_BUFFERTOOSMALL)// 0x80028016L
398 CASE_HRESULT(TYPE_E_INVDATAREAD)// 0x80028018L
399 CASE_HRESULT(TYPE_E_UNSUPFORMAT)// 0x80028019L
400 CASE_HRESULT(TYPE_E_REGISTRYACCESS)// 0x8002801CL
401 CASE_HRESULT(TYPE_E_LIBNOTREGISTERED)// 0x8002801DL
402 CASE_HRESULT(TYPE_E_UNDEFINEDTYPE)// 0x80028027L
403 CASE_HRESULT(TYPE_E_QUALIFIEDNAMEDISALLOWED)// 0x80028028L
404 CASE_HRESULT(TYPE_E_INVALIDSTATE)// 0x80028029L
405 CASE_HRESULT(TYPE_E_WRONGTYPEKIND)// 0x8002802AL
406 CASE_HRESULT(TYPE_E_ELEMENTNOTFOUND)// 0x8002802BL
407 CASE_HRESULT(TYPE_E_AMBIGUOUSNAME)// 0x8002802CL
408 CASE_HRESULT(TYPE_E_NAMECONFLICT)// 0x8002802DL
409 CASE_HRESULT(TYPE_E_UNKNOWNLCID)// 0x8002802EL
410 CASE_HRESULT(TYPE_E_DLLFUNCTIONNOTFOUND)// 0x8002802FL
411 CASE_HRESULT(TYPE_E_BADMODULEKIND)// 0x800288BDL
412 CASE_HRESULT(TYPE_E_SIZETOOBIG)// 0x800288C5L
413 CASE_HRESULT(TYPE_E_DUPLICATEID)// 0x800288C6L
414 CASE_HRESULT(TYPE_E_INVALIDID)// 0x800288CFL
415 CASE_HRESULT(TYPE_E_TYPEMISMATCH)// 0x80028CA0L
416 CASE_HRESULT(TYPE_E_OUTOFBOUNDS)// 0x80028CA1L
417 CASE_HRESULT(TYPE_E_IOERROR)// 0x80028CA2L
418 CASE_HRESULT(TYPE_E_CANTCREATETMPFILE)// 0x80028CA3L
419 CASE_HRESULT(TYPE_E_CANTLOADLIBRARY)// 0x80029C4AL
420 CASE_HRESULT(TYPE_E_INCONSISTENTPROPFUNCS)// 0x80029C83L
421 CASE_HRESULT(TYPE_E_CIRCULARTYPE)// 0x80029C84L
423 // ******************
425 // ******************
427 CASE_HRESULT(STG_E_INVALIDFUNCTION)// 0x80030001L
428 CASE_HRESULT(STG_E_FILENOTFOUND)// 0x80030002L
429 CASE_HRESULT(STG_E_PATHNOTFOUND)// 0x80030003L
430 CASE_HRESULT(STG_E_TOOMANYOPENFILES)// 0x80030004L
431 CASE_HRESULT(STG_E_ACCESSDENIED)// 0x80030005L
432 CASE_HRESULT(STG_E_INVALIDHANDLE)// 0x80030006L
433 CASE_HRESULT(STG_E_INSUFFICIENTMEMORY)// 0x80030008L
434 CASE_HRESULT(STG_E_INVALIDPOINTER)// 0x80030009L
435 CASE_HRESULT(STG_E_NOMOREFILES)// 0x80030012L
436 CASE_HRESULT(STG_E_DISKISWRITEPROTECTED)// 0x80030013L
437 CASE_HRESULT(STG_E_SEEKERROR)// 0x80030019L
438 CASE_HRESULT(STG_E_WRITEFAULT)// 0x8003001DL
439 CASE_HRESULT(STG_E_READFAULT)// 0x8003001EL
440 CASE_HRESULT(STG_E_SHAREVIOLATION)// 0x80030020L
441 CASE_HRESULT(STG_E_LOCKVIOLATION)// 0x80030021L
442 CASE_HRESULT(STG_E_FILEALREADYEXISTS)// 0x80030050L
443 CASE_HRESULT(STG_E_INVALIDPARAMETER)// 0x80030057L
444 CASE_HRESULT(STG_E_MEDIUMFULL)// 0x80030070L
445 CASE_HRESULT(STG_E_ABNORMALAPIEXIT)// 0x800300FAL
446 CASE_HRESULT(STG_E_INVALIDHEADER)// 0x800300FBL
447 CASE_HRESULT(STG_E_INVALIDNAME)// 0x800300FCL
448 CASE_HRESULT(STG_E_UNKNOWN)// 0x800300FDL
449 CASE_HRESULT(STG_E_UNIMPLEMENTEDFUNCTION)// 0x800300FEL
450 CASE_HRESULT(STG_E_INVALIDFLAG)// 0x800300FFL
451 CASE_HRESULT(STG_E_INUSE)// 0x80030100L
452 CASE_HRESULT(STG_E_NOTCURRENT)// 0x80030101L
453 CASE_HRESULT(STG_E_REVERTED)// 0x80030102L
454 CASE_HRESULT(STG_E_CANTSAVE)// 0x80030103L
455 CASE_HRESULT(STG_E_OLDFORMAT)// 0x80030104L
456 CASE_HRESULT(STG_E_OLDDLL)// 0x80030105L
457 CASE_HRESULT(STG_E_SHAREREQUIRED)// 0x80030106L
458 CASE_HRESULT(STG_E_NOTFILEBASEDSTORAGE)// 0x80030107L
459 CASE_HRESULT(STG_S_CONVERTED)// 0x00030200L
461 // ******************
463 // ******************
465 CASE_HRESULT(RPC_E_CALL_REJECTED)// 0x80010001L
466 CASE_HRESULT(RPC_E_CALL_CANCELED)// 0x80010002L
467 CASE_HRESULT(RPC_E_CANTPOST_INSENDCALL)// 0x80010003L
468 CASE_HRESULT(RPC_E_CANTCALLOUT_INASYNCCALL)// 0x80010004L
469 CASE_HRESULT(RPC_E_CANTCALLOUT_INEXTERNALCALL)// 0x80010005L
470 CASE_HRESULT(RPC_E_CONNECTION_TERMINATED)// 0x80010006L
471 CASE_HRESULT(RPC_E_SERVER_DIED)// 0x80010007L
472 CASE_HRESULT(RPC_E_CLIENT_DIED)// 0x80010008L
473 CASE_HRESULT(RPC_E_INVALID_DATAPACKET)// 0x80010009L
474 CASE_HRESULT(RPC_E_CANTTRANSMIT_CALL)// 0x8001000AL
475 CASE_HRESULT(RPC_E_CLIENT_CANTMARSHAL_DATA)// 0x8001000BL
476 CASE_HRESULT(RPC_E_CLIENT_CANTUNMARSHAL_DATA)// 0x8001000CL
477 CASE_HRESULT(RPC_E_SERVER_CANTMARSHAL_DATA)// 0x8001000DL
478 CASE_HRESULT(RPC_E_SERVER_CANTUNMARSHAL_DATA)// 0x8001000EL
479 CASE_HRESULT(RPC_E_INVALID_DATA)// 0x8001000FL
480 CASE_HRESULT(RPC_E_INVALID_PARAMETER)// 0x80010010L
481 CASE_HRESULT(RPC_E_CANTCALLOUT_AGAIN)// 0x80010011L
482 CASE_HRESULT(RPC_E_SERVER_DIED_DNE)// 0x80010012L
483 CASE_HRESULT(RPC_E_SYS_CALL_FAILED)// 0x80010100L
484 CASE_HRESULT(RPC_E_OUT_OF_RESOURCES)// 0x80010101L
485 CASE_HRESULT(RPC_E_ATTEMPTED_MULTITHREAD)// 0x80010102L
486 CASE_HRESULT(RPC_E_NOT_REGISTERED)// 0x80010103L
487 CASE_HRESULT(RPC_E_FAULT)// 0x80010104L
488 CASE_HRESULT(RPC_E_SERVERFAULT)// 0x80010105L
489 CASE_HRESULT(RPC_E_CHANGED_MODE)// 0x80010106L
490 CASE_HRESULT(RPC_E_INVALIDMETHOD)// 0x80010107L
491 CASE_HRESULT(RPC_E_DISCONNECTED)// 0x80010108L
492 CASE_HRESULT(RPC_E_RETRY)// 0x80010109L
493 CASE_HRESULT(RPC_E_SERVERCALL_RETRYLATER)// 0x8001010AL
494 CASE_HRESULT(RPC_E_SERVERCALL_REJECTED)// 0x8001010BL
495 CASE_HRESULT(RPC_E_INVALID_CALLDATA)// 0x8001010CL
496 CASE_HRESULT(RPC_E_CANTCALLOUT_ININPUTSYNCCALL)// 0x8001010DL
497 CASE_HRESULT(RPC_E_WRONG_THREAD)// 0x8001010EL
498 CASE_HRESULT(RPC_E_THREAD_NOT_INIT)// 0x8001010FL
499 CASE_HRESULT(RPC_E_UNEXPECTED)// 0x8001FFFFL
501 // ******************
503 // ******************
505 CASE_HRESULT(CTL_E_ILLEGALFUNCTIONCALL)
506 CASE_HRESULT(CTL_E_OVERFLOW)
507 CASE_HRESULT(CTL_E_OUTOFMEMORY)
508 CASE_HRESULT(CTL_E_DIVISIONBYZERO)
509 CASE_HRESULT(CTL_E_OUTOFSTRINGSPACE)
510 CASE_HRESULT(CTL_E_OUTOFSTACKSPACE)
511 CASE_HRESULT(CTL_E_BADFILENAMEORNUMBER)
512 CASE_HRESULT(CTL_E_FILENOTFOUND)
513 CASE_HRESULT(CTL_E_BADFILEMODE)
514 CASE_HRESULT(CTL_E_FILEALREADYOPEN)
515 CASE_HRESULT(CTL_E_DEVICEIOERROR)
516 CASE_HRESULT(CTL_E_FILEALREADYEXISTS)
517 CASE_HRESULT(CTL_E_BADRECORDLENGTH)
518 CASE_HRESULT(CTL_E_DISKFULL)
519 CASE_HRESULT(CTL_E_BADRECORDNUMBER)
520 CASE_HRESULT(CTL_E_BADFILENAME)
521 CASE_HRESULT(CTL_E_TOOMANYFILES)
522 CASE_HRESULT(CTL_E_DEVICEUNAVAILABLE)
523 CASE_HRESULT(CTL_E_PERMISSIONDENIED)
524 CASE_HRESULT(CTL_E_DISKNOTREADY)
525 CASE_HRESULT(CTL_E_PATHFILEACCESSERROR)
526 CASE_HRESULT(CTL_E_PATHNOTFOUND)
527 CASE_HRESULT(CTL_E_INVALIDPATTERNSTRING)
528 CASE_HRESULT(CTL_E_INVALIDUSEOFNULL)
529 CASE_HRESULT(CTL_E_INVALIDFILEFORMAT)
530 CASE_HRESULT(CTL_E_INVALIDPROPERTYVALUE)
531 CASE_HRESULT(CTL_E_INVALIDPROPERTYARRAYINDEX)
532 CASE_HRESULT(CTL_E_SETNOTSUPPORTEDATRUNTIME)
533 CASE_HRESULT(CTL_E_SETNOTSUPPORTED)
534 CASE_HRESULT(CTL_E_NEEDPROPERTYARRAYINDEX)
535 CASE_HRESULT(CTL_E_SETNOTPERMITTED)
536 CASE_HRESULT(CTL_E_GETNOTSUPPORTEDATRUNTIME)
537 CASE_HRESULT(CTL_E_GETNOTSUPPORTED)
538 CASE_HRESULT(CTL_E_PROPERTYNOTFOUND)
539 CASE_HRESULT(CTL_E_INVALIDCLIPBOARDFORMAT)
540 CASE_HRESULT(CTL_E_INVALIDPICTURE)
541 CASE_HRESULT(CTL_E_PRINTERERROR)
542 CASE_HRESULT(CTL_E_CANTSAVEFILETOTEMP)
543 CASE_HRESULT(CTL_E_SEARCHTEXTNOTFOUND)
544 CASE_HRESULT(CTL_E_REPLACEMENTSTOOLONG)
545 #endif // FEATURE_COMINTEROP
547 #ifdef _DEBUG // @todo: do we want to burn strings for this in a free build?
549 CASE_HRESULT(CEE_E_CVTRES_NOT_FOUND)
550 CASE_HRESULT(COR_E_APPDOMAINUNLOADED)
551 CASE_HRESULT(COR_E_CANNOTUNLOADAPPDOMAIN)
552 CASE_HRESULT(MSEE_E_ASSEMBLYLOADINPROGRESS)
553 CASE_HRESULT(COR_E_FIXUPSINEXE)
554 CASE_HRESULT(COR_E_MODULE_HASH_CHECK_FAILED)
555 CASE_HRESULT(FUSION_E_LOADFROM_BLOCKED)
556 CASE_HRESULT(FUSION_E_CACHEFILE_FAILED)
557 CASE_HRESULT(FUSION_E_REF_DEF_MISMATCH)
558 CASE_HRESULT(FUSION_E_INVALID_PRIVATE_ASM_LOCATION)
559 CASE_HRESULT(FUSION_E_ASM_MODULE_MISSING)
560 CASE_HRESULT(FUSION_E_PRIVATE_ASM_DISALLOWED)
561 CASE_HRESULT(FUSION_E_SIGNATURE_CHECK_FAILED)
562 CASE_HRESULT(FUSION_E_INVALID_NAME)
563 CASE_HRESULT(FUSION_E_CODE_DOWNLOAD_DISABLED)
564 CASE_HRESULT(CLDB_E_FILE_BADREAD)
565 CASE_HRESULT(CLDB_E_FILE_BADWRITE)
566 CASE_HRESULT(CLDB_S_TRUNCATION)
567 CASE_HRESULT(CLDB_E_FILE_OLDVER)
568 CASE_HRESULT(CLDB_E_SMDUPLICATE)
569 CASE_HRESULT(CLDB_E_NO_DATA)
570 CASE_HRESULT(CLDB_E_INCOMPATIBLE)
571 CASE_HRESULT(CLDB_E_FILE_CORRUPT)
572 CASE_HRESULT(CLDB_E_BADUPDATEMODE)
573 CASE_HRESULT(CLDB_E_INDEX_NOTFOUND)
574 CASE_HRESULT(CLDB_E_RECORD_NOTFOUND)
575 CASE_HRESULT(CLDB_E_RECORD_OUTOFORDER)
576 CASE_HRESULT(CLDB_E_TOO_BIG)
577 CASE_HRESULT(META_E_BADMETADATA)
578 CASE_HRESULT(META_E_BAD_SIGNATURE)
579 CASE_HRESULT(META_E_BAD_INPUT_PARAMETER)
580 CASE_HRESULT(META_E_CANNOTRESOLVETYPEREF)
581 CASE_HRESULT(META_S_DUPLICATE)
582 CASE_HRESULT(META_E_STRINGSPACE_FULL)
583 CASE_HRESULT(META_E_HAS_UNMARKALL)
584 CASE_HRESULT(META_E_MUST_CALL_UNMARKALL)
585 CASE_HRESULT(META_E_CA_INVALID_TARGET)
586 CASE_HRESULT(META_E_CA_INVALID_VALUE)
587 CASE_HRESULT(META_E_CA_INVALID_BLOB)
588 CASE_HRESULT(META_E_CA_REPEATED_ARG)
589 CASE_HRESULT(META_E_CA_UNKNOWN_ARGUMENT)
590 CASE_HRESULT(META_E_CA_UNEXPECTED_TYPE)
591 CASE_HRESULT(META_E_CA_INVALID_ARGTYPE)
592 CASE_HRESULT(META_E_CA_INVALID_ARG_FOR_TYPE)
593 CASE_HRESULT(META_E_CA_INVALID_UUID)
594 CASE_HRESULT(META_E_CA_INVALID_MARSHALAS_FIELDS)
595 CASE_HRESULT(META_E_CA_NT_FIELDONLY)
596 CASE_HRESULT(META_E_CA_NEGATIVE_PARAMINDEX)
597 CASE_HRESULT(META_E_CA_NEGATIVE_CONSTSIZE)
598 CASE_HRESULT(META_E_CA_FIXEDSTR_SIZE_REQUIRED)
599 CASE_HRESULT(META_E_CA_CUSTMARSH_TYPE_REQUIRED)
600 CASE_HRESULT(META_E_CA_BAD_FRIENDS_ARGS)
601 CASE_HRESULT(VLDTR_E_RID_OUTOFRANGE)
602 CASE_HRESULT(VLDTR_E_STRING_INVALID)
603 CASE_HRESULT(VLDTR_E_GUID_INVALID)
604 CASE_HRESULT(VLDTR_E_BLOB_INVALID)
605 CASE_HRESULT(VLDTR_E_MR_BADCALLINGCONV)
606 CASE_HRESULT(VLDTR_E_SIGNULL)
607 CASE_HRESULT(VLDTR_E_MD_BADCALLINGCONV)
608 CASE_HRESULT(VLDTR_E_MD_THISSTATIC)
609 CASE_HRESULT(VLDTR_E_MD_NOTTHISNOTSTATIC)
610 CASE_HRESULT(VLDTR_E_MD_NOARGCNT)
611 CASE_HRESULT(VLDTR_E_SIG_MISSELTYPE)
612 CASE_HRESULT(VLDTR_E_SIG_MISSTKN)
613 CASE_HRESULT(VLDTR_E_SIG_TKNBAD)
614 CASE_HRESULT(VLDTR_E_SIG_MISSFPTR)
615 CASE_HRESULT(VLDTR_E_SIG_MISSFPTRARGCNT)
616 CASE_HRESULT(VLDTR_E_SIG_MISSRANK)
617 CASE_HRESULT(VLDTR_E_SIG_MISSNSIZE)
618 CASE_HRESULT(VLDTR_E_SIG_MISSSIZE)
619 CASE_HRESULT(VLDTR_E_SIG_MISSNLBND)
620 CASE_HRESULT(VLDTR_E_SIG_MISSLBND)
621 CASE_HRESULT(VLDTR_E_SIG_BADELTYPE)
622 CASE_HRESULT(VLDTR_E_TD_ENCLNOTNESTED)
623 CASE_HRESULT(VLDTR_E_FMD_PINVOKENOTSTATIC)
624 CASE_HRESULT(VLDTR_E_SIG_SENTINMETHODDEF)
625 CASE_HRESULT(VLDTR_E_SIG_SENTMUSTVARARG)
626 CASE_HRESULT(VLDTR_E_SIG_MULTSENTINELS)
627 CASE_HRESULT(VLDTR_E_SIG_MISSARG)
628 CASE_HRESULT(VLDTR_E_SIG_BYREFINFIELD)
629 CASE_HRESULT(VLDTR_E_SIG_BADVOID)
630 CASE_HRESULT(CORDBG_E_UNRECOVERABLE_ERROR)
631 CASE_HRESULT(CORDBG_E_PROCESS_TERMINATED)
632 CASE_HRESULT(CORDBG_E_PROCESS_NOT_SYNCHRONIZED)
633 CASE_HRESULT(CORDBG_E_CLASS_NOT_LOADED)
634 CASE_HRESULT(CORDBG_E_IL_VAR_NOT_AVAILABLE)
635 CASE_HRESULT(CORDBG_E_BAD_REFERENCE_VALUE)
636 CASE_HRESULT(CORDBG_E_FIELD_NOT_AVAILABLE)
637 CASE_HRESULT(CORDBG_E_NON_NATIVE_FRAME)
638 CASE_HRESULT(CORDBG_E_CODE_NOT_AVAILABLE)
639 CASE_HRESULT(CORDBG_E_FUNCTION_NOT_IL)
640 CASE_HRESULT(CORDBG_S_BAD_START_SEQUENCE_POINT)
641 CASE_HRESULT(CORDBG_S_BAD_END_SEQUENCE_POINT)
642 CASE_HRESULT(CORDBG_E_CANT_SET_IP_INTO_FINALLY)
643 CASE_HRESULT(CORDBG_E_CANT_SET_IP_OUT_OF_FINALLY)
644 CASE_HRESULT(CORDBG_E_CANT_SET_IP_INTO_CATCH)
645 CASE_HRESULT(CORDBG_E_SET_IP_NOT_ALLOWED_ON_NONLEAF_FRAME)
646 CASE_HRESULT(CORDBG_E_SET_IP_IMPOSSIBLE)
647 CASE_HRESULT(CORDBG_E_FUNC_EVAL_BAD_START_POINT)
648 CASE_HRESULT(CORDBG_E_INVALID_OBJECT)
649 CASE_HRESULT(CORDBG_E_FUNC_EVAL_NOT_COMPLETE)
650 CASE_HRESULT(CORDBG_S_FUNC_EVAL_HAS_NO_RESULT)
651 CASE_HRESULT(CORDBG_S_VALUE_POINTS_TO_VOID)
652 CASE_HRESULT(CORDBG_S_FUNC_EVAL_ABORTED)
653 CASE_HRESULT(CORDBG_E_STATIC_VAR_NOT_AVAILABLE)
654 CASE_HRESULT(CORDBG_E_CANT_SETIP_INTO_OR_OUT_OF_FILTER)
655 CASE_HRESULT(CORDBG_E_CANT_CHANGE_JIT_SETTING_FOR_ZAP_MODULE)
656 CASE_HRESULT(CORDBG_E_CANT_SET_TO_JMC)
657 CASE_HRESULT(CORDBG_E_BAD_THREAD_STATE)
658 CASE_HRESULT(CORDBG_E_DEBUGGER_ALREADY_ATTACHED)
659 CASE_HRESULT(CORDBG_E_SUPERFLOUS_CONTINUE)
660 CASE_HRESULT(CORDBG_E_SET_VALUE_NOT_ALLOWED_ON_NONLEAF_FRAME)
661 CASE_HRESULT(CORDBG_E_ENC_MODULE_NOT_ENC_ENABLED)
662 CASE_HRESULT(CORDBG_E_SET_IP_NOT_ALLOWED_ON_EXCEPTION)
663 CASE_HRESULT(CORDBG_E_VARIABLE_IS_ACTUALLY_LITERAL)
664 CASE_HRESULT(CORDBG_E_PROCESS_DETACHED)
665 CASE_HRESULT(CORDBG_E_ENC_CANT_ADD_FIELD_TO_VALUE_OR_LAYOUT_CLASS)
666 CASE_HRESULT(CORDBG_E_FIELD_NOT_STATIC)
667 CASE_HRESULT(CORDBG_E_FIELD_NOT_INSTANCE)
668 CASE_HRESULT(CORDBG_E_ENC_JIT_CANT_UPDATE)
669 CASE_HRESULT(CORDBG_E_ENC_INTERNAL_ERROR)
670 CASE_HRESULT(CORDBG_E_ENC_HANGING_FIELD)
671 CASE_HRESULT(CORDBG_E_MODULE_NOT_LOADED)
672 CASE_HRESULT(CORDBG_E_UNABLE_TO_SET_BREAKPOINT)
673 CASE_HRESULT(CORDBG_E_DEBUGGING_NOT_POSSIBLE)
674 CASE_HRESULT(CORDBG_E_KERNEL_DEBUGGER_ENABLED)
675 CASE_HRESULT(CORDBG_E_KERNEL_DEBUGGER_PRESENT)
676 CASE_HRESULT(CORDBG_E_INCOMPATIBLE_PROTOCOL)
677 CASE_HRESULT(CORDBG_E_TOO_MANY_PROCESSES)
678 CASE_HRESULT(CORDBG_E_INTEROP_NOT_SUPPORTED)
679 CASE_HRESULT(CORDBG_E_NO_REMAP_BREAKPIONT)
680 CASE_HRESULT(CORDBG_E_OBJECT_NEUTERED)
681 CASE_HRESULT(CORPROF_E_FUNCTION_NOT_COMPILED)
682 CASE_HRESULT(CORPROF_E_DATAINCOMPLETE)
683 CASE_HRESULT(CORPROF_E_FUNCTION_NOT_IL)
684 CASE_HRESULT(CORPROF_E_NOT_MANAGED_THREAD)
685 CASE_HRESULT(CORPROF_E_CALL_ONLY_FROM_INIT)
686 CASE_HRESULT(CORPROF_E_NOT_YET_AVAILABLE)
687 CASE_HRESULT(SECURITY_E_INCOMPATIBLE_SHARE)
688 CASE_HRESULT(SECURITY_E_UNVERIFIABLE)
689 CASE_HRESULT(SECURITY_E_INCOMPATIBLE_EVIDENCE)
690 CASE_HRESULT(CLDB_E_INTERNALERROR)
691 CASE_HRESULT(CORSEC_E_POLICY_EXCEPTION)
692 CASE_HRESULT(CORSEC_E_MIN_GRANT_FAIL)
693 CASE_HRESULT(CORSEC_E_NO_EXEC_PERM)
694 CASE_HRESULT(CORSEC_E_XMLSYNTAX)
695 CASE_HRESULT(CORSEC_E_INVALID_STRONGNAME)
696 CASE_HRESULT(CORSEC_E_MISSING_STRONGNAME)
697 CASE_HRESULT(CORSEC_E_INVALID_IMAGE_FORMAT)
698 CASE_HRESULT(CORSEC_E_CRYPTO)
699 CASE_HRESULT(CORSEC_E_CRYPTO_UNEX_OPER)
700 CASE_HRESULT(CORSECATTR_E_BAD_ACTION)
701 CASE_HRESULT(COR_E_APPLICATION)
702 CASE_HRESULT(COR_E_ARGUMENTOUTOFRANGE)
703 CASE_HRESULT(COR_E_ARITHMETIC)
704 CASE_HRESULT(COR_E_ARRAYTYPEMISMATCH)
705 CASE_HRESULT(COR_E_CONTEXTMARSHAL)
706 CASE_HRESULT(COR_E_TIMEOUT)
707 CASE_HRESULT(COR_E_DIVIDEBYZERO)
708 CASE_HRESULT(COR_E_EXCEPTION)
709 CASE_HRESULT(COR_E_EXECUTIONENGINE)
710 CASE_HRESULT(COR_E_FIELDACCESS)
711 CASE_HRESULT(COR_E_FORMAT)
712 CASE_HRESULT(COR_E_BADIMAGEFORMAT)
713 CASE_HRESULT(COR_E_ASSEMBLYEXPECTED)
714 CASE_HRESULT(COR_E_TYPEUNLOADED)
715 CASE_HRESULT(COR_E_INDEXOUTOFRANGE)
716 CASE_HRESULT(COR_E_INVALIDOPERATION)
717 CASE_HRESULT(COR_E_INVALIDPROGRAM)
718 CASE_HRESULT(COR_E_MEMBERACCESS)
719 CASE_HRESULT(COR_E_METHODACCESS)
720 CASE_HRESULT(COR_E_MISSINGFIELD)
721 CASE_HRESULT(COR_E_MISSINGMANIFESTRESOURCE)
722 CASE_HRESULT(COR_E_MISSINGMEMBER)
723 CASE_HRESULT(COR_E_MISSINGMETHOD)
724 CASE_HRESULT(COR_E_MULTICASTNOTSUPPORTED)
725 CASE_HRESULT(COR_E_NOTFINITENUMBER)
726 CASE_HRESULT(COR_E_DUPLICATEWAITOBJECT)
727 CASE_HRESULT(COR_E_PLATFORMNOTSUPPORTED)
728 CASE_HRESULT(COR_E_NOTSUPPORTED)
729 CASE_HRESULT(COR_E_OVERFLOW)
730 CASE_HRESULT(COR_E_RANK)
731 CASE_HRESULT(COR_E_SECURITY)
732 CASE_HRESULT(COR_E_SERIALIZATION)
733 CASE_HRESULT(COR_E_STACKOVERFLOW)
734 CASE_HRESULT(COR_E_SYNCHRONIZATIONLOCK)
735 CASE_HRESULT(COR_E_SYSTEM)
736 CASE_HRESULT(COR_E_THREADABORTED)
737 CASE_HRESULT(COR_E_THREADINTERRUPTED)
738 CASE_HRESULT(COR_E_THREADSTATE)
739 CASE_HRESULT(COR_E_THREADSTOP)
740 CASE_HRESULT(COR_E_TYPEINITIALIZATION)
741 CASE_HRESULT(COR_E_TYPELOAD)
742 CASE_HRESULT(COR_E_ENTRYPOINTNOTFOUND)
743 CASE_HRESULT(COR_E_DLLNOTFOUND)
744 CASE_HRESULT(COR_E_VERIFICATION)
745 CASE_HRESULT(COR_E_INVALIDCOMOBJECT)
746 CASE_HRESULT(COR_E_MARSHALDIRECTIVE)
747 CASE_HRESULT(COR_E_INVALIDOLEVARIANTTYPE)
748 CASE_HRESULT(COR_E_SAFEARRAYTYPEMISMATCH)
749 CASE_HRESULT(COR_E_SAFEARRAYRANKMISMATCH)
750 CASE_HRESULT(COR_E_INVALIDFILTERCRITERIA)
751 CASE_HRESULT(COR_E_REFLECTIONTYPELOAD)
752 CASE_HRESULT(COR_E_TARGET)
753 CASE_HRESULT(COR_E_TARGETINVOCATION)
754 CASE_HRESULT(COR_E_CUSTOMATTRIBUTEFORMAT)
755 CASE_HRESULT(COR_E_ENDOFSTREAM)
756 CASE_HRESULT(COR_E_FILELOAD)
757 CASE_HRESULT(COR_E_FILENOTFOUND)
758 CASE_HRESULT(COR_E_IO)
759 CASE_HRESULT(COR_E_DIRECTORYNOTFOUND)
760 CASE_HRESULT(COR_E_PATHTOOLONG)
761 CASE_HRESULT(COR_E_OBJECTDISPOSED)
762 CASE_HRESULT(COR_E_NEWER_RUNTIME)
763 CASE_HRESULT(CLR_E_SHIM_RUNTIMELOAD)
764 CASE_HRESULT(VER_E_FIELD_SIG)
765 CASE_HRESULT(CORDBG_E_THREAD_NOT_SCHEDULED)
777 // ---------------------------------------------------------------------------
778 // HRException class. Implements exception API for exceptions from HRESULTS
779 // ---------------------------------------------------------------------------
781 HRESULT HRException::GetHR()
783 LIMITED_METHOD_DAC_CONTRACT;
787 // ---------------------------------------------------------------------------
788 // COMException class. - moved to COMEx.cpp
789 // ---------------------------------------------------------------------------
791 // ---------------------------------------------------------------------------
792 // SEHException class. Implements exception API for SEH exception info
793 // ---------------------------------------------------------------------------
795 HRESULT SEHException::GetHR()
797 LIMITED_METHOD_DAC_CONTRACT;
799 if (IsComPlusException(&m_exception)) // EE exception
800 return (HRESULT) m_exception.ExceptionInformation[0];
802 return m_exception.ExceptionCode;
805 IErrorInfo *SEHException::GetErrorInfo()
807 LIMITED_METHOD_CONTRACT;
811 void SEHException::GetMessage(SString &string)
815 if (IsComPlusException(&m_exception)) // EE exception
817 GenerateTopLevelHRExceptionMessage(GetHR(), string);
821 if (m_exception.ExceptionCode != 0)
823 string.Printf("Exception code 0x%.8x", m_exception.ExceptionCode);
827 // If we don't have a valid exception code, then give a generic message that's a little nicer than
828 // "code 0x00000000".
829 string.Printf("Unknown exception");
834 //==============================================================================
835 // DelegatingException class. Implements exception API for "foreign" exceptions.
836 //==============================================================================
838 DelegatingException::DelegatingException()
839 : m_delegatedException((Exception*)DELEGATE_NOT_YET_SET)
841 LIMITED_METHOD_DAC_CONTRACT;
842 } // DelegatingException::DelegatingException()
844 //------------------------------------------------------------------------------
845 DelegatingException::~DelegatingException()
849 // If there is a valid delegate pointer (inited and non-NULL), delete it.
850 if (IsDelegateValid())
851 Delete(m_delegatedException);
854 m_delegatedException = NULL;
855 } // DelegatingException::~DelegatingException()
857 //------------------------------------------------------------------------------
858 // Retrieve the delegating exception, or get one from the Thread, or get NULL.
859 Exception* DelegatingException::GetDelegate()
863 // If we haven't gotten the exception pointer before..
864 if (!IsDelegateSet())
866 // .. get it now. NULL in case there isn't one and we take default action.
867 m_delegatedException = NULL;
868 GetLastThrownObjectExceptionFromThread(reinterpret_cast<void**>(&m_delegatedException));
871 return m_delegatedException;
872 } // Exception* DelegatingException::GetDelegate()
874 //------------------------------------------------------------------------------
876 HRESULT DelegatingException::GetHR()
879 SUPPORTS_DAC_HOST_ONLY;
881 // Retrieve any delegating exception.
882 Exception *pDelegate = GetDelegate();
884 // If there is a delegate exception, defer to it. Otherwise,
885 // default to E_FAIL.
886 return pDelegate ? pDelegate->GetHR() : E_FAIL;
888 } // HRESULT DelegatingException::GetHR()
890 //------------------------------------------------------------------------------
891 IErrorInfo *DelegatingException::GetErrorInfo()
895 // Retrieve any delegating exception.
896 Exception *pDelegate = GetDelegate();
898 // If there is a delegate exception, defer to it. Otherwise,
900 return pDelegate ? pDelegate->GetErrorInfo() : NULL;
902 } // IErrorInfo *DelegatingException::GetErrorInfo()
904 //------------------------------------------------------------------------------
905 void DelegatingException::GetMessage(SString &result)
909 // Retrieve any delegating exception.
910 Exception *pDelegate = GetDelegate();
912 // If there is a delegate exception, defer to it. Otherwise,
913 // default to a generic message.
916 pDelegate->GetMessage(result);
920 // If we don't have a valid exception code, then give a generic message
921 // that's a little nicer than "code 0x00000000".
922 result.Printf("Unknown exception");
924 } // void DelegatingException::GetMessage()
926 //------------------------------------------------------------------------------
927 Exception *DelegatingException::Clone()
931 // Clone the base exception, this will also take care of cloning the inner
932 // exception if there is one.
933 NewHolder<DelegatingException> retExcep((DelegatingException*)Exception::Clone());
935 // If there is a valid delegating exception...
936 if (IsDelegateValid())
938 retExcep->m_delegatedException = m_delegatedException->Clone();
941 { // ... but if there is not, just copy -- either NULL or DELEGATE_NOT_YET_SET
942 retExcep->m_delegatedException = m_delegatedException;
945 retExcep.SuppressRelease();
947 } // virtual Exception *DelegatingException::Clone()
949 //==============================================================================
950 //==============================================================================
952 void DECLSPEC_NORETURN ThrowHR(HRESULT hr)
956 STRESS_LOG1(LF_EH, LL_INFO100, "ThrowHR: HR = %x\n", hr);
958 if (hr == E_OUTOFMEMORY)
961 // Catchers assume only failing hresults
962 _ASSERTE(FAILED(hr));
966 EX_THROW(HRException, (hr));
969 void DECLSPEC_NORETURN ThrowHR(HRESULT hr, SString const &msg)
973 STRESS_LOG1(LF_EH, LL_INFO100, "ThrowHR: HR = %x\n", hr);
975 if (hr == E_OUTOFMEMORY)
978 // Catchers assume only failing hresults
979 _ASSERTE(FAILED(hr));
983 EX_THROW(HRMsgException, (hr, msg));
986 void DECLSPEC_NORETURN ThrowHR(HRESULT hr, UINT uText)
989 SUPPORTS_DAC_HOST_ONLY;
991 if (hr == E_OUTOFMEMORY)
994 // Catchers assume only failing hresults
995 _ASSERTE(FAILED(hr));
999 SString sExceptionText;
1001 // We won't check the return value here. If it fails, we'll just
1003 sExceptionText.LoadResource(CCompRC::Error, uText);
1005 EX_THROW(HRMsgException, (hr, sExceptionText));
1008 void DECLSPEC_NORETURN ThrowWin32(DWORD err)
1010 WRAPPER_NO_CONTRACT;
1011 if (err == ERROR_NOT_ENOUGH_MEMORY)
1017 ThrowHR(HRESULT_FROM_WIN32(err));
1021 void DECLSPEC_NORETURN ThrowLastError()
1023 WRAPPER_NO_CONTRACT;
1026 ThrowWin32(GetLastError());
1029 void DECLSPEC_NORETURN ThrowOutOfMemory()
1039 #ifndef DACCESS_COMPILE
1041 // Use volatile store to prevent compiler from optimizing the static variable away
1042 VolatileStoreWithoutBarrier<HRESULT>(&g_hrFatalError, COR_E_OUTOFMEMORY);
1044 // Regular CLR builds - throw our pre-created OOM exception object
1045 PAL_CPP_THROW(Exception *, Exception::GetOOMException());
1049 // DAC builds - raise a DacError
1050 DacError(E_OUTOFMEMORY);
1052 // DacError always throws but isn't marked DECLSPEC_NORETURN so we have to
1053 // tell the compiler that this code is unreachable. We could mark DacError
1054 // (and DacNotImpl) as DECLSPEC_NORETURN, but then we've have to update a
1055 // lot of code where we do something afterwards. Also, due to inlining,
1056 // we'd sometimes have to change functions which call functions that only
1057 // call DacNotImpl. I have these changes in a bbpack and some of them look
1058 // nice, but I'm not sure if it's worth the risk of merge conflicts.
1064 #include "corexcep.h"
1066 //--------------------------------------------------------------------------------
1067 // Helper for EX_THROW_WITH_INNER()
1069 // Clones an exception into the current domain. Also handles special cases for
1070 // OOM and other stuff. Making this a function so we don't inline all this logic
1071 // every place we call EX_THROW_WITH_INNER.
1073 // If the "inner" is a transient exception such as OOM or ThreadAbort, this function
1074 // will just throw it rather than allow it to be wrapped in another exception.
1075 //--------------------------------------------------------------------------------
1076 Exception *ExThrowWithInnerHelper(Exception *inner)
1085 // Yes, NULL is a legal case. Makes it easier to author uniform helpers for
1086 // both wrapped and normal exceptions.
1092 if (inner == Exception::GetOOMException())
1094 // We don't want to do allocations if we're already throwing an OOM!
1095 PAL_CPP_THROW(Exception*, inner);
1098 inner = inner->DomainBoundClone();
1100 // It isn't useful to wrap OOMs and StackOverflows in other exceptions. Just throw them now.
1102 if (inner->IsTransient())
1104 PAL_CPP_THROW(Exception*, inner);
1112 #pragma optimize("", off)
1115 void ExThrowTrap(const char *fcn, const char *file, int line, const char *szType, HRESULT hr, const char *args)
1122 #pragma optimize("", on)
1130 //-------------------------------------------------------------------------------------------
1131 // This routine will generate the most descriptive possible error message for an hresult.
1132 // It will generate at minimum the hex value. It will also try to generate the symbolic name
1133 // (E_POINTER) and the friendly description (from the message tables.)
1135 // bNoGeekStuff suppresses hex HR codes. Use this sparingly as most error strings generated by the
1136 // CLR are aimed at developers, not end-users.
1137 //-------------------------------------------------------------------------------------------
1138 void GetHRMsg(HRESULT hr, SString &result, BOOL bNoGeekStuff/* = FALSE*/)
1147 result = W(""); // Make sure this routine isn't an inadvertent data-leak exploit!
1152 BOOL fHaveDescr = FALSE;
1154 if (FAILED(hr) && HRESULT_FACILITY(hr) == FACILITY_URT && HRESULT_CODE(hr) < MAX_URT_HRESULT_CODE)
1156 fHaveDescr = strDescr.LoadResource(CCompRC::Error, MSG_FOR_URT_HR(hr));
1160 DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM;
1161 dwFlags |= FORMAT_MESSAGE_MAX_WIDTH_MASK;
1163 fHaveDescr = strDescr.FormatMessage(dwFlags, 0, hr, 0);
1166 LPCSTR name = Exception::GetHRSymbolicName(hr);
1168 // If we can't get a resource string, print the hresult regardless.
1171 bNoGeekStuff = FALSE;
1176 result.Append(strDescr);
1183 result.Append(W(" ("));
1186 result.AppendPrintf(W("0x%.8X"), hr);
1189 result.AppendPrintf(W(" (%S)"), name);
1194 result.Append(W(")"));
1200 //-------------------------------------------------------------------------------------------
1201 // Similar to GetHRMsg but phrased for top-level exception message.
1202 //-------------------------------------------------------------------------------------------
1203 void GenerateTopLevelHRExceptionMessage(HRESULT hresult, SString &result)
1212 result = W(""); // Make sure this routine isn't an inadvertent data-leak exploit!
1214 GetHRMsg(hresult, result);
1217 #if !defined(DACCESS_COMPILE)
1219 void GetCurrentExceptionPointers(PEXCEPTION_POINTERS pExceptionInfo)
1221 WRAPPER_NO_CONTRACT;
1223 PEXCEPTION_RECORD pRecord = (PEXCEPTION_RECORD)ClrFlsGetValue(TlsIdx_PEXCEPTION_RECORD);
1224 PCONTEXT pContext = (PCONTEXT)ClrFlsGetValue(TlsIdx_PCONTEXT);
1226 pExceptionInfo->ContextRecord = pContext;
1227 pExceptionInfo->ExceptionRecord = pRecord;
1230 if (pRecord != NULL)
1232 _ASSERTE ((PVOID)(pRecord) > (PVOID)(&pRecord));
1236 #endif // !defined(DACCESS_COMPILE)
1238 DWORD GetCurrentExceptionCode()
1240 WRAPPER_NO_CONTRACT;
1241 SUPPORTS_DAC_HOST_ONLY;
1243 return (DWORD)(size_t)ClrFlsGetValue(TlsIdx_EXCEPTION_CODE);
1246 //===========================================================================================
1247 // These abstractions hide the difference between legacy desktop CLR's (that don't support
1248 // side-by-side-inproc and rely on a fixed SEH code to identify managed exceptions) and
1249 // new CLR's that support side-by-side inproc.
1251 // The new CLR's use a different set of SEH codes to avoid conflicting with the legacy CLR's.
1252 // In addition, to distinguish between EH's raised by different inproc instances of the CLR,
1253 // the module handle of the owning CLR is stored in ExceptionRecord.ExceptionInformation[4].
1255 // (Note: all existing SEH's use either only slot [0] or no slots at all. We are leaving
1256 // slots [1] thru [3] open for future expansion.)
1257 //===========================================================================================
1259 // Is this exception code one of the special CLR-specific SEH codes that participate in the
1260 // instance-tagging scheme?
1261 BOOL IsInstanceTaggedSEHCode(DWORD dwExceptionCode)
1263 LIMITED_METHOD_DAC_CONTRACT;
1265 return dwExceptionCode == EXCEPTION_COMPLUS;
1268 // This set of overloads generates the NumberParameters and ExceptionInformation[] array to
1269 // pass to RaiseException().
1272 // exceptionArgs: a fixed-size array of size INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE.
1273 // This will get filled in by this function. (The module handle goes
1274 // in the last slot if this is a side-by-side-inproc enabled build.)
1276 // exceptionArg1... up to four arguments that go in slots [0]..[3]. These depends
1277 // the specific requirements of your exception code.
1280 // The NumberParameters to pass to RaiseException().
1282 // Basically, this is either INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE or the count of your
1283 // fixed arguments depending on whether this tagged-SEH-enabled build.
1285 // This function is not permitted to fail.
1287 // (the existing system can support more overloads up to 4 fixed arguments but we don't need them at this time.)
1289 static DWORD MarkAsThrownByUsWorker(UINT numArgs, /*out*/ ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE], ULONG_PTR arg0 = 0)
1291 STATIC_CONTRACT_NOTHROW;
1292 STATIC_CONTRACT_GC_NOTRIGGER;
1293 STATIC_CONTRACT_FORBID_FAULT;
1296 _ASSERTE(numArgs < INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE);
1297 FillMemory(exceptionArgs, sizeof(ULONG_PTR) * INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE, 0);
1299 exceptionArgs[0] = arg0;
1301 #if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES)
1302 exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] = (ULONG_PTR) (GetCLRModule());
1303 #endif // !defined(FEATURE_UTILCODE_NO_DEPENDENCIES)
1305 return INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE;
1308 DWORD MarkAsThrownByUs(/*out*/ ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE])
1310 STATIC_CONTRACT_NOTHROW;
1311 STATIC_CONTRACT_GC_NOTRIGGER;
1312 STATIC_CONTRACT_FORBID_FAULT;
1314 return MarkAsThrownByUsWorker(0, exceptionArgs);
1317 DWORD MarkAsThrownByUs(/*out*/ ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE], ULONG_PTR arg0)
1319 STATIC_CONTRACT_NOTHROW;
1320 STATIC_CONTRACT_GC_NOTRIGGER;
1321 STATIC_CONTRACT_FORBID_FAULT;
1323 return MarkAsThrownByUsWorker(1, exceptionArgs, arg0);
1326 // Given an exception record, checks if it's exception code matches a specific exception code
1327 // *and* whether it was tagged by the calling instance of the CLR.
1329 // If this is a non-tagged-SEH-enabled build, it is blindly assumed to be tagged by the
1330 // calling instance of the CLR.
1331 BOOL WasThrownByUs(const EXCEPTION_RECORD *pcER, DWORD dwExceptionCode)
1333 STATIC_CONTRACT_NOTHROW;
1334 STATIC_CONTRACT_GC_NOTRIGGER;
1335 STATIC_CONTRACT_FORBID_FAULT;
1336 STATIC_CONTRACT_SUPPORTS_DAC;
1338 _ASSERTE(IsInstanceTaggedSEHCode(dwExceptionCode));
1339 _ASSERTE(pcER != NULL);
1340 if (dwExceptionCode != pcER->ExceptionCode)
1345 if (pcER->NumberParameters != INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE)
1349 #if!defined(FEATURE_UTILCODE_NO_DEPENDENCIES)
1350 if ( ((ULONG_PTR)(GetCLRModule())) != pcER->ExceptionInformation[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] )
1355 #else // !(!defined(FEATURE_UTILCODE_NO_DEPENDENCIES)
1357 #endif // !defined(FEATURE_UTILCODE_NO_DEPENDENCIES)
1362 //-----------------------------------------------------------------------------------
1363 // The following group wraps the basic abstracts specifically for EXCEPTION_COMPLUS.
1364 //-----------------------------------------------------------------------------------
1365 BOOL IsComPlusException(const EXCEPTION_RECORD *pcER)
1367 STATIC_CONTRACT_WRAPPER;
1369 return WasThrownByUs(pcER, EXCEPTION_COMPLUS);
1372 VOID RaiseComPlusException()
1374 STATIC_CONTRACT_THROWS;
1375 STATIC_CONTRACT_GC_NOTRIGGER;
1376 STATIC_CONTRACT_FORBID_FAULT;
1379 ULONG_PTR exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE];
1380 DWORD numParams = MarkAsThrownByUs(exceptionArgs);
1381 RaiseException(EXCEPTION_COMPLUS, 0, numParams, exceptionArgs);
1384 //===========================================================================================
1385 //===========================================================================================