ExceptionHelper.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using Jint.Runtime.CallStack;
  3. namespace Jint.Runtime
  4. {
  5. internal static class ExceptionHelper
  6. {
  7. public static void ThrowSyntaxError(Engine engine, string message = null)
  8. {
  9. throw new JavaScriptException(engine.SyntaxError, message);
  10. }
  11. public static T ThrowArgumentException<T>(string message = null)
  12. {
  13. ThrowArgumentException(message);
  14. return default;
  15. }
  16. public static void ThrowArgumentException(string message = null)
  17. {
  18. ThrowArgumentException(message, null);
  19. }
  20. public static void ThrowArgumentException(string message, string paramName)
  21. {
  22. throw new ArgumentException(message, paramName);
  23. }
  24. public static void ThrowReferenceError(Engine engine, string message = null)
  25. {
  26. throw new JavaScriptException(engine.ReferenceError, message);
  27. }
  28. public static T ThrowTypeError<T>(Engine engine, string message = null, Exception exception = null)
  29. {
  30. ThrowTypeError(engine, message, exception);
  31. return default;
  32. }
  33. public static void ThrowTypeError(Engine engine, string message = null, Exception exception = null)
  34. {
  35. throw new JavaScriptException(engine.TypeError, message, exception);
  36. }
  37. public static void ThrowRangeError(Engine engine, string message = null)
  38. {
  39. throw new JavaScriptException(engine.RangeError, message);
  40. }
  41. public static void ThrowUriError(Engine engine)
  42. {
  43. throw new JavaScriptException(engine.UriError);
  44. }
  45. public static void ThrowNotImplementedException()
  46. {
  47. throw new NotImplementedException();
  48. }
  49. public static void ThrowArgumentOutOfRangeException(string paramName, string message)
  50. {
  51. throw new ArgumentOutOfRangeException(paramName, message);
  52. }
  53. public static void ThrowTimeoutException()
  54. {
  55. throw new TimeoutException();
  56. }
  57. public static void ThrowStatementsCountOverflowException()
  58. {
  59. throw new StatementsCountOverflowException();
  60. }
  61. public static void ThrowArgumentOutOfRangeException()
  62. {
  63. throw new ArgumentOutOfRangeException();
  64. }
  65. public static T ThrowNotSupportedException<T>(string message = null)
  66. {
  67. throw new NotSupportedException(message);
  68. }
  69. public static void ThrowNotSupportedException(string message = null)
  70. {
  71. throw new NotSupportedException(message);
  72. }
  73. public static void ThrowInvalidOperationException(string message = null)
  74. {
  75. throw new InvalidOperationException(message);
  76. }
  77. public static void ThrowJavaScriptException(string message)
  78. {
  79. throw new JavaScriptException("TypeError");
  80. }
  81. public static void ThrowRecursionDepthOverflowException(JintCallStack currentStack, string currentExpressionReference)
  82. {
  83. throw new RecursionDepthOverflowException(currentStack, currentExpressionReference);
  84. }
  85. public static void ThrowArgumentNullException(string paramName)
  86. {
  87. throw new ArgumentNullException(paramName);
  88. }
  89. public static T ThrowArgumentNullException<T>(string paramName)
  90. {
  91. throw new ArgumentNullException(paramName);
  92. }
  93. public static void ThrowError(Engine engine, string message)
  94. {
  95. throw new JavaScriptException(engine.Error, message);
  96. }
  97. public static void ThrowPlatformNotSupportedException(string message)
  98. {
  99. throw new PlatformNotSupportedException(message);
  100. }
  101. public static void ThrowMemoryLimitExceededException(string message)
  102. {
  103. throw new MemoryLimitExceededException(message);
  104. }
  105. }
  106. }