Exception.h 4.8 KB

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