-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathExceptionHelper.cs
More file actions
69 lines (54 loc) · 2.54 KB
/
ExceptionHelper.cs
File metadata and controls
69 lines (54 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Reflection;
using IL2CPU.API.Attribs;
namespace Cosmos.IL2CPU
{
[ForceInclude]
public static class ExceptionHelper
{
#pragma warning disable CA2211 // Non-constant fields should not be visible
public static Exception CurrentException;
#pragma warning restore CA2211 // Non-constant fields should not be visible
public static void ThrowArgumentOutOfRange(string aError)
{
Console.WriteLine(aError);
throw new ArgumentOutOfRangeException(aError);
}
public static void ThrowDivideByZeroException() => throw new DivideByZeroException();
public static void ThrowIndexOutOfRangeException() => throw new IndexOutOfRangeException();
public static void ThrowInvalidOperation(string aError)
{
Console.WriteLine(aError);
throw new InvalidOperationException(aError);
}
public static void ThrowNotImplemented(string aError)
{
Console.WriteLine(aError);
throw new NotImplementedException(aError);
}
public static void ThrowOverflow()
{
string xError = "Arithmetic operation or conversion causes an overflow!";
throw new OverflowException(xError);
}
public static void ThrowNotFiniteNumberException(double offendingNumber)
{
throw new NotFiniteNumberException(offendingNumber);
}
public static void ThrowInvalidCastException() => throw new InvalidCastException();
}
public static class ExceptionHelperRefs
{
public static readonly FieldInfo CurrentExceptionRef = typeof(ExceptionHelper).GetField("CurrentException");
public static readonly MethodInfo ThrowOverflowExceptionRef =
typeof(ExceptionHelper).GetMethod(nameof(ExceptionHelper.ThrowOverflow));
public static readonly MethodInfo ThrowDivideByZeroExceptionRef =
typeof(ExceptionHelper).GetMethod(nameof(ExceptionHelper.ThrowDivideByZeroException));
public static readonly MethodInfo ThrowInvalidCastExceptionRef =
typeof(ExceptionHelper).GetMethod(nameof(ExceptionHelper.ThrowInvalidCastException));
public static readonly MethodInfo ThrowNotFiniteNumberExceptionRef =
typeof(ExceptionHelper).GetMethod(nameof(ExceptionHelper.ThrowNotFiniteNumberException));
public static readonly MethodInfo ThrowIndexOutOfRangeException =
typeof(ExceptionHelper).GetMethod(nameof(ExceptionHelper.ThrowIndexOutOfRangeException));
}
}