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.
4//====================================================================
5
6//
7// Purpose: Lists the commonly-used Runtime Exceptions visible to users.
8//
9
10//
11//====================================================================
12
13// If you add an exception, modify CorError.h to add an HResult there.
14// (Guidelines for picking a unique number for your HRESULT are in CorError.h)
15// Also modify your managed Exception class to include its HResult.
16// Modify __HResults in the same directory as your exception, to include
17// your new HResult. And of course, add your exception and symbolic
18// name for your HResult to the list below so it can be thrown from
19// within the EE and recognized in Interop scenarios.
20
21
22// This is an exhaustive list of all exceptions that can be
23// thrown by the EE itself. If you add to this list the IL spec
24// needs to be updated!
25
26// Note: When multiple exceptions map to the same hresult it is very important
27// that the exception that should be created when the hresult in question
28// is returned by a function be FIRST in the list.
29//
30
31
32//
33// These are the macro's that need to be implemented before this file is included.
34//
35
36//
37// EXCEPTION_BEGIN_DEFINE(ns, reKind, bHRformessage, ...)
38//
39// This macro starts an exception definition.
40//
41// ns Namespace of the exception.
42// reKind Name of the exception.
43// bHRformessage When the exception is thrown from the EE, if this argument is true
44// the EE will create a string with the HRESULT, so that you get a more
45// meaningful error message than let's say AssemblyLoadException.
46// Usually you want to set this to true if your exception corresponds to
47// more than one HRESULT.
48// ... The list of HRESULTs that map to this exception. The first of the list
49// is used as the representative HRESULT for the reKind value.
50//
51
52//
53// #define EXCEPTION_ADD_HR(hr)
54//
55// This macro adds an additional HRESULT that maps to the exception.
56//
57// hr Additional HRESULT that maps to the exception.
58//
59
60//
61// #define EXCEPTION_END_DEFINE()
62//
63// This macro terminates the exception definition.
64//
65
66
67//
68// Namespaces used to define the exceptions.
69//
70
71
72
73#include "namespace.h"
74
75
76// Temporary workaround - adding some HRESULTs that the Jupiter team will define and
77// add to one of their header files for errors. Once these have been RI'ed into
78// windows and are in a file adjacent to winerror.h, we can remove these constants.
79// Given integration time, remove this by August 2011 at the very latest.
80#ifndef E_XAMLPARSEFAILED
81#define E_XAMLPARSEFAILED _HRESULT_TYPEDEF_(0x802B000AL)
82#endif
83#ifndef E_LAYOUTCYCLE
84#define E_LAYOUTCYCLE _HRESULT_TYPEDEF_(0x802B0014L)
85#endif
86#ifndef E_ELEMENTNOTENABLED
87#define E_ELEMENTNOTENABLED _HRESULT_TYPEDEF_(0x802B001EL)
88#endif
89#ifndef E_ELEMENTNOTAVAILABLE
90#define E_ELEMENTNOTAVAILABLE _HRESULT_TYPEDEF_(0x802B001FL)
91#endif
92#ifndef RO_E_CLOSED
93#define RO_E_CLOSED _HRESULT_TYPEDEF_(0x80000013L)
94#endif
95#ifndef APPMODEL_ERROR_NO_PACKAGE
96#define APPMODEL_ERROR_NO_PACKAGE 15700L
97#endif
98
99//
100// Actual definition of the exceptions and their matching HRESULT's.
101// HRESULTs are expected to be defined in CorError.h, and must also be
102// redefined in managed code in an __HResults class. The managed exception
103// object MUST use the same HRESULT in all of its constructors for COM Interop.
104// Read comments near top of this file.
105//
106//
107// NOTE: Please keep this list sorted according to the name of the exception.
108//
109//
110
111DEFINE_EXCEPTION(g_ReflectionNS, AmbiguousMatchException, false, COR_E_AMBIGUOUSMATCH)
112DEFINE_EXCEPTION(g_SystemNS, ApplicationException, false, COR_E_APPLICATION)
113DEFINE_EXCEPTION(g_SystemNS, ArithmeticException, false, COR_E_ARITHMETIC)
114
115DEFINE_EXCEPTION(g_SystemNS, ArgumentException, false,
116 COR_E_ARGUMENT, STD_CTL_SCODE(449), STD_CTL_SCODE(450), CLR_E_BIND_UNRECOGNIZED_IDENTITY_FORMAT)
117
118DEFINE_EXCEPTION(g_SystemNS, ArgumentOutOfRangeException, false, COR_E_ARGUMENTOUTOFRANGE, HRESULT_FROM_WIN32(ERROR_NO_UNICODE_TRANSLATION))
119DEFINE_EXCEPTION(g_SystemNS, ArrayTypeMismatchException, false, COR_E_ARRAYTYPEMISMATCH)
120
121// Keep in sync with the list in EEFileLoadException::GetFileLoadKind in clrex.cpp
122DEFINE_EXCEPTION(g_SystemNS, BadImageFormatException, true,
123 COR_E_BADIMAGEFORMAT, CLDB_E_FILE_OLDVER,
124 CLDB_E_INDEX_NOTFOUND,
125 CLDB_E_FILE_CORRUPT, COR_E_NEWER_RUNTIME,
126 COR_E_ASSEMBLYEXPECTED,
127 HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT),
128 HRESULT_FROM_WIN32(ERROR_EXE_MARKED_INVALID),
129 CORSEC_E_INVALID_IMAGE_FORMAT,
130 HRESULT_FROM_WIN32(ERROR_NOACCESS),
131 HRESULT_FROM_WIN32(ERROR_INVALID_ORDINAL),
132 HRESULT_FROM_WIN32(ERROR_INVALID_DLL),
133 HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT),
134 IDS_CLASSLOAD_32BITCLRLOADING64BITASSEMBLY,
135 COR_E_LOADING_REFERENCE_ASSEMBLY,
136 META_E_BAD_SIGNATURE,
137 COR_E_LOADING_WINMD_REFERENCE_ASSEMBLY)
138
139// CannotUnloadAppDomainException is removed in CoreCLR
140#define kCannotUnloadAppDomainException kException
141
142DEFINE_EXCEPTION(g_CodeContractsNS, ContractException, false, COR_E_CODECONTRACTFAILED)
143
144
145DEFINE_EXCEPTION(g_ReflectionNS, CustomAttributeFormatException, false, COR_E_CUSTOMATTRIBUTEFORMAT)
146
147DEFINE_EXCEPTION(g_CryptographyNS, CryptographicException, false, CORSEC_E_CRYPTO)
148
149DEFINE_EXCEPTION(g_SystemNS, DataMisalignedException, false, COR_E_DATAMISALIGNED)
150
151DEFINE_EXCEPTION(g_IONS, DirectoryNotFoundException, true, COR_E_DIRECTORYNOTFOUND, STG_E_PATHNOTFOUND, CTL_E_PATHNOTFOUND)
152
153DEFINE_EXCEPTION(g_SystemNS, DivideByZeroException, false, COR_E_DIVIDEBYZERO, CTL_E_DIVISIONBYZERO)
154
155DEFINE_EXCEPTION(g_SystemNS, DllNotFoundException, false, COR_E_DLLNOTFOUND)
156DEFINE_EXCEPTION(g_SystemNS, DuplicateWaitObjectException, false, COR_E_DUPLICATEWAITOBJECT)
157
158DEFINE_EXCEPTION(g_IONS, EndOfStreamException, false, COR_E_ENDOFSTREAM, STD_CTL_SCODE(62))
159
160DEFINE_EXCEPTION(g_SystemNS, EntryPointNotFoundException, false, COR_E_ENTRYPOINTNOTFOUND)
161DEFINE_EXCEPTION(g_SystemNS, Exception, false, COR_E_EXCEPTION)
162DEFINE_EXCEPTION(g_SystemNS, ExecutionEngineException, false, COR_E_EXECUTIONENGINE)
163
164DEFINE_EXCEPTION(g_SystemNS, FieldAccessException, false, COR_E_FIELDACCESS)
165
166DEFINE_EXCEPTION(g_IONS, FileLoadException, true,
167 COR_E_FILELOAD, FUSION_E_INVALID_PRIVATE_ASM_LOCATION,
168 FUSION_E_SIGNATURE_CHECK_FAILED,
169 FUSION_E_LOADFROM_BLOCKED, FUSION_E_CACHEFILE_FAILED,
170 FUSION_E_ASM_MODULE_MISSING, FUSION_E_INVALID_NAME,
171 FUSION_E_PRIVATE_ASM_DISALLOWED, FUSION_E_HOST_GAC_ASM_MISMATCH,
172 COR_E_MODULE_HASH_CHECK_FAILED, FUSION_E_REF_DEF_MISMATCH,
173 SECURITY_E_INCOMPATIBLE_SHARE, SECURITY_E_INCOMPATIBLE_EVIDENCE,
174 SECURITY_E_UNVERIFIABLE, COR_E_FIXUPSINEXE, HRESULT_FROM_WIN32(ERROR_TOO_MANY_OPEN_FILES),
175 HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), HRESULT_FROM_WIN32(ERROR_LOCK_VIOLATION),
176 HRESULT_FROM_WIN32(ERROR_OPEN_FAILED), HRESULT_FROM_WIN32(ERROR_DISK_CORRUPT),
177 HRESULT_FROM_WIN32(ERROR_UNRECOGNIZED_VOLUME),
178 HRESULT_FROM_WIN32(ERROR_DLL_INIT_FAILED),
179 FUSION_E_CODE_DOWNLOAD_DISABLED, CORSEC_E_MISSING_STRONGNAME,
180 MSEE_E_ASSEMBLYLOADINPROGRESS,
181 HRESULT_FROM_WIN32(ERROR_FILE_INVALID))
182
183DEFINE_EXCEPTION(g_IONS, FileNotFoundException, true,
184 HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
185 HRESULT_FROM_WIN32(ERROR_INVALID_NAME), CTL_E_FILENOTFOUND,
186 HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), HRESULT_FROM_WIN32(ERROR_BAD_NET_NAME),
187 HRESULT_FROM_WIN32(ERROR_BAD_NETPATH), HRESULT_FROM_WIN32(ERROR_NOT_READY),
188 HRESULT_FROM_WIN32(ERROR_WRONG_TARGET_NAME), INET_E_UNKNOWN_PROTOCOL,
189 INET_E_CONNECTION_TIMEOUT, INET_E_CANNOT_CONNECT, INET_E_RESOURCE_NOT_FOUND,
190 INET_E_OBJECT_NOT_FOUND, INET_E_DOWNLOAD_FAILURE, INET_E_DATA_NOT_AVAILABLE,
191 HRESULT_FROM_WIN32(ERROR_DLL_NOT_FOUND),
192 CLR_E_BIND_ASSEMBLY_VERSION_TOO_LOW, CLR_E_BIND_ASSEMBLY_PUBLIC_KEY_MISMATCH,
193 CLR_E_BIND_ASSEMBLY_NOT_FOUND)
194
195DEFINE_EXCEPTION(g_SystemNS, FormatException, false, COR_E_FORMAT)
196
197DEFINE_EXCEPTION(g_SystemNS, IndexOutOfRangeException, false, COR_E_INDEXOUTOFRANGE, 0x800a0009 /*Subscript out of range*/)
198DEFINE_EXCEPTION(g_SystemNS, InsufficientExecutionStackException, false, COR_E_INSUFFICIENTEXECUTIONSTACK)
199DEFINE_EXCEPTION(g_SystemNS, InvalidCastException, false, COR_E_INVALIDCAST)
200#ifdef FEATURE_COMINTEROP
201DEFINE_EXCEPTION(g_InteropNS, InvalidComObjectException, false, COR_E_INVALIDCOMOBJECT)
202#endif //FEATURE_COMINTEROP
203DEFINE_EXCEPTION(g_ReflectionNS, InvalidFilterCriteriaException, false, COR_E_INVALIDFILTERCRITERIA)
204DEFINE_EXCEPTION(g_InteropNS, InvalidOleVariantTypeException, false, COR_E_INVALIDOLEVARIANTTYPE)
205
206DEFINE_EXCEPTION(g_SystemNS, InvalidOperationException, false, COR_E_INVALIDOPERATION)
207
208#ifdef FEATURE_COMINTEROP
209DEFINE_EXCEPTION_HR_WINRT_ONLY(g_SystemNS, InvalidOperationException, COR_E_INVALIDOPERATION,
210 E_ILLEGAL_STATE_CHANGE,
211 E_ILLEGAL_METHOD_CALL,
212 E_ILLEGAL_DELEGATE_ASSIGNMENT,
213 HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE))
214#endif // FEATURE_COMINTEROP
215
216DEFINE_EXCEPTION(g_SystemNS, InvalidProgramException, false, COR_E_INVALIDPROGRAM)
217
218DEFINE_EXCEPTION(g_IONS, IOException, false, COR_E_IO, CTL_E_DEVICEIOERROR, STD_CTL_SCODE(31036), STD_CTL_SCODE(31037))
219
220DEFINE_EXCEPTION(g_InteropNS, MarshalDirectiveException, false, COR_E_MARSHALDIRECTIVE)
221DEFINE_EXCEPTION(g_SystemNS, MethodAccessException, false, COR_E_METHODACCESS, META_E_CA_FRIENDS_SN_REQUIRED)
222DEFINE_EXCEPTION(g_SystemNS, MemberAccessException, false, COR_E_MEMBERACCESS)
223DEFINE_EXCEPTION(g_SystemNS, MissingFieldException, false, COR_E_MISSINGFIELD)
224DEFINE_EXCEPTION(g_ResourcesNS, MissingManifestResourceException, false,COR_E_MISSINGMANIFESTRESOURCE)
225
226DEFINE_EXCEPTION(g_SystemNS, MissingMemberException, false, COR_E_MISSINGMEMBER, STD_CTL_SCODE(461))
227
228DEFINE_EXCEPTION(g_SystemNS, MissingMethodException, false, COR_E_MISSINGMETHOD)
229DEFINE_EXCEPTION(g_SystemNS, MulticastNotSupportedException, false, COR_E_MULTICASTNOTSUPPORTED)
230
231DEFINE_EXCEPTION(g_SystemNS, NotFiniteNumberException, false, COR_E_NOTFINITENUMBER)
232
233DEFINE_EXCEPTION(g_SystemNS, NotSupportedException, false, COR_E_NOTSUPPORTED, STD_CTL_SCODE(438), STD_CTL_SCODE(445), STD_CTL_SCODE(458), STD_CTL_SCODE(459))
234
235DEFINE_EXCEPTION(g_SystemNS, NullReferenceException, false, COR_E_NULLREFERENCE)
236// Note: this has to come after NullReferenceException since we want NullReferenceException to be created
237// when E_POINTER is returned from COM interfaces.
238DEFINE_EXCEPTION(g_SystemNS, AccessViolationException, false, E_POINTER)
239
240DEFINE_EXCEPTION(g_SystemNS, ObjectDisposedException, false, COR_E_OBJECTDISPOSED, RO_E_CLOSED)
241
242DEFINE_EXCEPTION(g_SystemNS, OperationCanceledException, false, COR_E_OPERATIONCANCELED)
243
244DEFINE_EXCEPTION(g_SystemNS, OverflowException, false, COR_E_OVERFLOW, CTL_E_OVERFLOW)
245
246DEFINE_EXCEPTION(g_IONS, PathTooLongException, false, COR_E_PATHTOOLONG)
247
248DEFINE_EXCEPTION(g_SystemNS, PlatformNotSupportedException, false, COR_E_PLATFORMNOTSUPPORTED)
249
250DEFINE_EXCEPTION(g_SystemNS, RankException, false, COR_E_RANK)
251DEFINE_EXCEPTION(g_ReflectionNS, ReflectionTypeLoadException, false, COR_E_REFLECTIONTYPELOAD)
252DEFINE_EXCEPTION(g_CompilerServicesNS, RuntimeWrappedException, false, COR_E_RUNTIMEWRAPPED)
253
254
255DEFINE_EXCEPTION(g_SecurityNS, SecurityException, true,
256 COR_E_SECURITY, CORSEC_E_INVALID_STRONGNAME,
257 CTL_E_PERMISSIONDENIED, STD_CTL_SCODE(419),
258 CORSEC_E_INVALID_PUBLICKEY, CORSEC_E_SIGNATURE_MISMATCH)
259
260#if FEATURE_COMINTEROP
261DEFINE_EXCEPTION(g_InteropNS, SafeArrayRankMismatchException, false, COR_E_SAFEARRAYRANKMISMATCH)
262DEFINE_EXCEPTION(g_InteropNS, SafeArrayTypeMismatchException, false, COR_E_SAFEARRAYTYPEMISMATCH)
263#endif //FEATURE_COMINTEROP
264DEFINE_EXCEPTION(g_SerializationNS, SerializationException, false, COR_E_SERIALIZATION)
265
266DEFINE_EXCEPTION(g_SystemNS, StackOverflowException, false, COR_E_STACKOVERFLOW, CTL_E_OUTOFSTACKSPACE)
267
268DEFINE_EXCEPTION(g_ThreadingNS, SynchronizationLockException, false, COR_E_SYNCHRONIZATIONLOCK)
269DEFINE_EXCEPTION(g_SystemNS, SystemException, false, COR_E_SYSTEM)
270
271DEFINE_EXCEPTION(g_ReflectionNS, TargetException, false, COR_E_TARGET)
272DEFINE_EXCEPTION(g_ReflectionNS, TargetInvocationException, false, COR_E_TARGETINVOCATION)
273DEFINE_EXCEPTION(g_ReflectionNS, TargetParameterCountException, false, COR_E_TARGETPARAMCOUNT)
274DEFINE_EXCEPTION(g_ThreadingNS, ThreadAbortException, false, COR_E_THREADABORTED)
275DEFINE_EXCEPTION(g_ThreadingNS, ThreadInterruptedException, false, COR_E_THREADINTERRUPTED)
276DEFINE_EXCEPTION(g_ThreadingNS, ThreadStateException, false, COR_E_THREADSTATE)
277DEFINE_EXCEPTION(g_ThreadingNS, ThreadStartException, false, COR_E_THREADSTART)
278DEFINE_EXCEPTION(g_SystemNS, TypeAccessException, false, COR_E_TYPEACCESS)
279DEFINE_EXCEPTION(g_SystemNS, TypeInitializationException, false, COR_E_TYPEINITIALIZATION)
280
281#ifdef FEATURE_COMINTEROP
282DEFINE_EXCEPTION(g_SystemNS, TypeLoadException, false, COR_E_TYPELOAD,
283 RO_E_METADATA_NAME_NOT_FOUND, CLR_E_BIND_TYPE_NOT_FOUND)
284#else
285DEFINE_EXCEPTION(g_SystemNS, TypeLoadException, false, COR_E_TYPELOAD)
286#endif
287
288DEFINE_EXCEPTION(g_SystemNS, TypeUnloadedException, false, COR_E_TYPEUNLOADED)
289
290DEFINE_EXCEPTION(g_SystemNS, UnauthorizedAccessException, true, COR_E_UNAUTHORIZEDACCESS, CTL_E_PATHFILEACCESSERROR, STD_CTL_SCODE(335))
291
292DEFINE_EXCEPTION(g_SecurityNS, VerificationException, false, COR_E_VERIFICATION)
293
294
295DEFINE_EXCEPTION(g_InteropNS, COMException, false, E_FAIL)
296DEFINE_EXCEPTION(g_InteropNS, ExternalException, false, E_FAIL)
297DEFINE_EXCEPTION(g_InteropNS, SEHException, false, E_FAIL)
298DEFINE_EXCEPTION(g_SystemNS, NotImplementedException, false, E_NOTIMPL)
299
300DEFINE_EXCEPTION(g_SystemNS, OutOfMemoryException, false, E_OUTOFMEMORY, CTL_E_OUTOFMEMORY, STD_CTL_SCODE(31001))
301
302
303DEFINE_EXCEPTION(g_SystemNS, ArgumentNullException, false, E_POINTER)
304
305#define kLastExceptionInMscorlib kArgumentNullException
306
307//
308// All exceptions defined in other .NET Framework assemblies have to be at the end
309//
310
311#ifdef FEATURE_COMINTEROP
312// Jupiter needs some HRESULTs mapped to exceptions in .NET Framework assemblies other than mscorlib.
313DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(g_MarkupNS, XamlParseException, "System.Runtime.WindowsRuntime.UI.Xaml", ECMA_PUBLICKEY_STR, false, E_XAMLPARSEFAILED)
314DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(g_AutomationNS, ElementNotAvailableException, "System.Runtime.WindowsRuntime.UI.Xaml", ECMA_PUBLICKEY_STR, false, E_ELEMENTNOTAVAILABLE)
315DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(g_AutomationNS, ElementNotEnabledException, "System.Runtime.WindowsRuntime.UI.Xaml", ECMA_PUBLICKEY_STR, false, E_ELEMENTNOTENABLED)
316DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(g_DirectUINS, LayoutCycleException, "System.Runtime.WindowsRuntime.UI.Xaml", ECMA_PUBLICKEY_STR, false, E_LAYOUTCYCLE)
317#endif // FEATURE_COMINTEROP
318
319
320// Please see comments on at the top of this list
321
322#undef DEFINE_EXCEPTION
323#undef DEFINE_EXCEPTION_HR_WINRT_ONLY
324#undef DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY
325