Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CrashWatcher.cs
Go to the documentation of this file.
1using System;
3using System.IO;
7
8namespace Terraria.Utilities;
9
10public static class CrashWatcher
11{
12 public static bool LogAllExceptions { get; set; }
13
14 public static bool DumpOnException { get; set; }
15
16 public static bool DumpOnCrash { get; private set; }
17
18 public static CrashDump.Options CrashDumpOptions { get; private set; }
19
20 private static string DumpPath => Path.Combine(Main.SavePath, "Dumps");
21
22 public static void Inititialize()
23 {
24 Console.WriteLine("Error Logging Enabled.");
25 AppDomain.CurrentDomain.FirstChanceException += delegate(object sender, FirstChanceExceptionEventArgs exceptionArgs)
26 {
27 if (LogAllExceptions && 0 == 0)
28 {
29 string text2 = PrintException(exceptionArgs.Exception);
30 Console.Write(string.Concat("================\r\n" + $"{DateTime.Now}: First-Chance Exception\r\nThread: {Thread.CurrentThread.ManagedThreadId} [{Thread.CurrentThread.Name}]\r\nCulture: {Thread.CurrentThread.CurrentCulture.Name}\r\nException: {text2}\r\n", "================\r\n\r\n"));
31 }
32 };
33 AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs exceptionArgs)
34 {
35 string text = PrintException((Exception)exceptionArgs.ExceptionObject);
36 Console.Write(string.Concat("================\r\n" + $"{DateTime.Now}: Unhandled Exception\r\nThread: {Thread.CurrentThread.ManagedThreadId} [{Thread.CurrentThread.Name}]\r\nCulture: {Thread.CurrentThread.CurrentCulture.Name}\r\nException: {text}\r\n", "================\r\n"));
37 if (DumpOnCrash)
38 {
40 }
41 };
42 }
43
44 private static string PrintException(Exception ex)
45 {
46 string text = ex.ToString();
47 try
48 {
49 int num = (int)typeof(Exception).GetProperty("HResult", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).GetGetMethod(nonPublic: true).Invoke(ex, null);
50 if (num != 0)
51 {
52 text = text + "\nHResult: " + num;
53 }
54 }
55 catch
56 {
57 }
59 {
60 Exception[] loaderExceptions = ((ReflectionTypeLoadException)ex).LoaderExceptions;
61 foreach (Exception ex2 in loaderExceptions)
62 {
63 text = text + "\n+--> " + PrintException(ex2);
64 }
65 }
66 return text;
67 }
68
70 {
71 DumpOnCrash = true;
73 }
74
75 public static void DisableCrashDumps()
76 {
77 DumpOnCrash = false;
78 }
79
80 [Conditional("DEBUG")]
81 private static void HookDebugExceptionDialog()
82 {
83 }
84}
static void Write(string format, object? arg0)
Definition Console.cs:850
static void WriteLine()
Definition Console.cs:733
override string ToString()
Definition Exception.cs:384
static string Combine(string path1, string path2)
Definition Path.cs:304
static string SavePath
Definition Main.cs:2680
static bool WriteException(Options options, string outputDirectory=".")
Definition CrashDump.cs:55
static CrashDump.Options CrashDumpOptions
static string PrintException(Exception ex)
static void EnableCrashDumps(CrashDump.Options options)