Does it make sense to write a minidump on Unhandled Exception in .NET?

It seems when I go about handling exceptions:

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

      

Or like this:

Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;

      

The stack has already shut down to call my handled exception handler. There doesn't seem to be any point in writing a minidump at this point, because the stack is already being unwound. Without unwinding, the stack application cannot figure out if this exception was unhandled or not.

Even though I can see the stack at UnhandledExceptionEventArgs.ExceptionObject, I cannot get a minidump at the exact location where the application crashed.

Is there another way?

I know I can ask the system to write a dump, but for that I have to be an administrator.

UPDATE:

Ok. I have an idea) It would be nice if in the FirstChanceException handler I could go back and see if this exception was not handled or not. But it has to be fast enough to work in production.

+3


source to share


2 answers


You are looking for an FirstChanceException

event
that is raised before the stack unwinds.



+1


source


I have never used landfills. This is usually enough to know only where the exception occurs. But you are right, it would be much more convenient to know the values, etc. In the most recent version of the error logger, I even pass up to 3 optional parameters that are dumped to the log, it helps. Something like (simplified):

public void Log(string tag, string message = "", Exception exception = null, [CallerMemberName] string caller = "",
    object param = null, object param2 = null, object param3 = null, object param4 = null)
{
    DateTime time = DateTime.Now;
    var method = caller;
    if (param != null || param2 != null || param3 != null)
        method = string.Format("{0}({1}{2}{3}{4})", caller, param != null ? param : "", param2 != null ? ", " + param2 : "",
            param3 != null ? ", " + param3 : "", param4 != null ? ", " + param4 : "");
    try
    {
        ...
        if (exception != null)
            using (StreamWriter file = new StreamWriter(_errorFileName, true))
            {
                file.WriteLine(string.Format("[{0}] {1} {2}: {3}", time, tag, method, message));
                file.WriteLine(exception);
            }
    }
    catch { }
}

      

And use



public static T Deserialize<T>(string file)
{
    try
    {
        ...
    }
    catch (Exception e)
    {
        Log("xml", exception: e, param: file, param2: typeof(T));
    }
    return default(T);

      

}

This is not an answer to your question, but a decision on how to live comfortably without a dump.

0


source







All Articles