Exception.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include <stdint.h>
  3. #include "il2cpp-config.h"
  4. #include "utils/Il2CppError.h"
  5. #include "utils/StringView.h"
  6. #include "il2cpp-class-internals.h"
  7. struct Il2CppException;
  8. struct Il2CppImage;
  9. struct Il2CppClass;
  10. namespace il2cpp
  11. {
  12. namespace vm
  13. {
  14. class TypeNameParseInfo;
  15. class LIBIL2CPP_CODEGEN_API Exception
  16. {
  17. // exported
  18. public:
  19. static Il2CppException* Get(il2cpp_hresult_t hresult, bool defaultToCOMException);
  20. static void PrepareExceptionForThrow(Il2CppException* ex, MethodInfo* lastManagedFrame = NULL);
  21. static NORETURN void Raise(Il2CppException* ex, MethodInfo* lastManagedFrame = NULL);
  22. static NORETURN void Rethrow(Il2CppException* ex);
  23. static NORETURN void RaiseOutOfMemoryException();
  24. static NORETURN void RaiseOutOfMemoryException(const utils::StringView<Il2CppChar>& msg);
  25. static NORETURN void RaiseNullReferenceException();
  26. static NORETURN void RaiseNullReferenceException(const utils::StringView<Il2CppChar>& msg);
  27. static NORETURN void RaiseDivideByZeroException();
  28. static NORETURN void RaiseIndexOutOfRangeException();
  29. static NORETURN void RaiseOverflowException();
  30. static NORETURN void RaiseArgumentOutOfRangeException(const char* msg);
  31. static NORETURN void Raise(il2cpp_hresult_t hresult, bool defaultToCOMException);
  32. static void RaiseIfError(const utils::Il2CppError& error);
  33. inline static void RaiseIfFailed(il2cpp_hresult_t hresult, bool defaultToCOMException)
  34. {
  35. if (IL2CPP_HR_FAILED(hresult))
  36. Raise(hresult, defaultToCOMException);
  37. }
  38. ////TODO: rename to NewFromClassNameAndMessage
  39. static Il2CppException* FromNameMsg(const Il2CppImage* image, const char* name_space, const char* name, const char* msg);
  40. static Il2CppException* FromNameMsg(const Il2CppImage* image, const char* name_space, const char* name, const utils::StringView<Il2CppChar>& msg);
  41. static Il2CppException* FromNameMsg(const Il2CppImage* image, const char* name_space, const char* name, const utils::StringView<Il2CppChar>& msg, il2cpp_hresult_t hresult);
  42. public:
  43. ////TODO: rename all of these to NewXXX
  44. static Il2CppException* GetArgumentException(const char *arg, const char *msg);
  45. static Il2CppException* GetArgumentException(const utils::StringView<Il2CppChar>& arg, const utils::StringView<Il2CppChar>& msg);
  46. static Il2CppException* GetArgumentNullException(const char *arg);
  47. static Il2CppException* GetArgumentOutOfRangeException(const char *arg);
  48. static Il2CppException* GetTypeInitializationException(const char *msg, Il2CppException* innerException);
  49. static Il2CppException* GetIndexOutOfRangeException();
  50. static Il2CppException* GetIndexOutOfRangeException(const utils::StringView<Il2CppChar>& msg);
  51. static Il2CppException* GetNullReferenceException(const utils::StringView<Il2CppChar>& msg);
  52. static Il2CppException* GetInvalidCastException(const char* msg);
  53. static Il2CppException* GetInvalidCastException(const utils::StringView<Il2CppChar>& msg);
  54. static Il2CppException* GetTypeLoadException();
  55. static Il2CppException* GetTypeLoadException(const TypeNameParseInfo& typeNameParseInfo);
  56. static Il2CppException* GetTypeLoadException(const utils::StringView<char>& namespaze, const utils::StringView<char>& typeName, const utils::StringView<char>& assemblyName);
  57. static Il2CppException* GetTypeLoadExceptionForWindowsRuntimeType(const utils::StringView<char>& namespaze, const utils::StringView<char>& typeName);
  58. static Il2CppException* GetOutOfMemoryException(const utils::StringView<Il2CppChar>& msg);
  59. static Il2CppException* GetOverflowException();
  60. static Il2CppException* GetOverflowException(const char* msg);
  61. static Il2CppException* GetFormatException(const char* msg);
  62. static Il2CppException* GetSystemException();
  63. static Il2CppException* GetNotSupportedException(const char* msg);
  64. static Il2CppException* GetArrayTypeMismatchException();
  65. static Il2CppException* GetTypeLoadException(const char* msg);
  66. static Il2CppException* GetEntryPointNotFoundException(const char* msg);
  67. static Il2CppException* GetAmbiguousImplementationException(const char* msg);
  68. static Il2CppException* GetDllNotFoundException(const char* msg);
  69. static Il2CppException* GetInvalidOperationException(const char* msg);
  70. static Il2CppException* GetThreadInterruptedException();
  71. static Il2CppException* GetThreadAbortException();
  72. static Il2CppException* GetThreadStateException(const char* msg);
  73. static Il2CppException* GetSynchronizationLockException(const char* msg);
  74. static Il2CppException* GetMissingMethodException(const char* msg);
  75. static Il2CppException* GetMarshalDirectiveException(const char* msg);
  76. static Il2CppException* GetTargetException(const char* msg);
  77. static Il2CppException* GetMethodAccessException(const char* msg);
  78. static Il2CppException* GetExecutionEngineException(const char* msg);
  79. static Il2CppException* GetUnauthorizedAccessException(const utils::StringView<Il2CppChar>& msg);
  80. static Il2CppException* GetUnauthorizedAccessException(const char* msg);
  81. static Il2CppException* GetDivideByZeroException();
  82. static Il2CppException* GetPlatformNotSupportedException(const utils::StringView<Il2CppChar>& msg);
  83. static Il2CppException* GetFileLoadException(const char* msg);
  84. static Il2CppException* GetFileNotFoundException(const utils::StringView<Il2CppChar>& msg);
  85. static Il2CppException* GetCustomAttributeFormatException(const char* msg);
  86. static Il2CppException* GetMaximumNestedGenericsException();
  87. static void StoreExceptionInfo(Il2CppException* ex, Il2CppString* exceptionString);
  88. };
  89. } /* namespace vm */
  90. } /* namespace il2cpp */