summary Exceptions that cannot be catched in AppThreadException We can

 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
/// <summary>
/// Exceptions that cannot be catched in AppThreadException.
/// We cannot cancel crashing of application there.
/// We just logging special info and show stadart message.
/// </summary>
private void AppDomain_OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
string typeName = "[null]";
string isTerminating = "[null]";
if (e != null)
{
if (e.ExceptionObject != null)
typeName = e.ExceptionObject.GetType().Name;
isTerminating = e.IsTerminating.ToString();
}
AGMessages.WriteInLog("Unhandled error. Raising standart unhandled thread exceptions procedure.\nBy the way, Exception type "
+ typeName + " and thread terminating == " + isTerminating
, MessageBoxIcon.Error);
ThreadExceptionEventArgs ea = new ThreadExceptionEventArgs((e ?? new UnhandledExceptionEventArgs(new Exception("[null]"), false)).ExceptionObject as Exception ?? new Exception("[Without exception]"));
AppThreadException(this, ea);
}
catch (Exception ex)
{
Exception exsource = ((Exception)((e ?? new UnhandledExceptionEventArgs(new Exception("[null]"), false)).ExceptionObject ?? new Exception("no exception object")));
MessageBox.Show("Error in error handler."
+ "\nSource error " + (exsource.Message ?? "")
+ "\nStackTrace " + (exsource.StackTrace ?? "")
+ "\n\nHandler error " + (ex.Message ?? "")
+ "\nStackTrace " + (ex.StackTrace ?? "")
, "Unlogged error"
, MessageBoxButtons.OK
, MessageBoxIcon.Error);
//throw ex;
}
}