Skip to content

Instantly share code, notes, and snippets.

@UltraSabreman
Last active August 29, 2015 14:04
Show Gist options
  • Save UltraSabreman/0918e7aaf6453b18361f to your computer and use it in GitHub Desktop.
Save UltraSabreman/0918e7aaf6453b18361f to your computer and use it in GitHub Desktop.
Dumps an C# exception to the console in a some-what formatted fasion. (Uses my varardic print function).
public static void DumpException(Exception e) {
Func<int, String> getEquals = (count) => {
String s = "";
for (int i = 0; i < count; i++)
s += "=";
return s;
};
PrintLine(ConsoleColor.White, ConsoleColor.Red, "====EXCEPTION====");
PrintLine(ConsoleColor.White, "=MSG: ", ConsoleColor.Red, e.Message);
PrintLine(ConsoleColor.White, "=SRC: ", ConsoleColor.Red, e.Source);
PrintLine(ConsoleColor.White, "=TGT: ", ConsoleColor.Red, e.TargetSite);
PrintLine(ConsoleColor.White, "=ST : ", ConsoleColor.Red, e.StackTrace);
e = e.InnerException;
int ind = 1;
while (e != null) {
String eq = getEquals(ind++);
PrintLine(ConsoleColor.White, ConsoleColor.Red, eq + "===EXCEPTION====");
PrintLine(ConsoleColor.White, eq + "MSG: ", ConsoleColor.Red, e.Message);
PrintLine(ConsoleColor.White, eq + "SRC: ", ConsoleColor.Red, e.Source);
PrintLine(ConsoleColor.White, eq + "TGT: ", ConsoleColor.Red, e.TargetSite);
PrintLine(ConsoleColor.White, eq + "ST : ", ConsoleColor.Red, e.StackTrace);
e = e.InnerException;
}
PrintLine(ConsoleColor.White, ConsoleColor.Red, "=================");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment