0

I'm using Caliburn.Micro and added my own ErrorHandler using log4net. That's how it looks like:

  protected internal void Handle<T>(T exception)
    {
        try
        {
            MessageBox.Show((exception as Exception)?.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            Logger.Error((exception as Exception)?.Message, exception as Exception);
        }
        catch (Exception ex)
        {
            Logger.Error($"ErrorHandler (Handle<T>) throws exception {ex.Message}");
            Logger.Error("$^", ex);
            MessageBox.Show(ex.Message);
        }
    }

And at some other place:

try
{
     ...
}
catch (Exception ex)
{
    ErrorHandler.Handle(ex);
}

Now that some exception's thrown, ErrorHandler.Handle(ex) comes into play. However, it throws out this error:

An exception of type 'System.NullReferenceException' occurred in SampleProject.exe but was not handled in user code

Additional information: Object reference not set to an instance of an object.

TBH, I don't know where to start the investigation at this point...?

John
  • 197
  • 1
  • 2
  • 22
  • 2
    `MessageBox.Show(ex.Message);` Replace by `ex.ToString()` to have the full stacktrace and understand where the error comes from. Or simply put a breakpoint inside of your `try` block and manually inspect the variables. Given how simple the code is, it's probably `Logger` that is null – Kevin Gosse Dec 11 '16 at 12:37
  • @KevinGosse Actually, the problem came from a different place. However, that's not how such a logger is supposed to work, as it throws an exception when handling the error. Any idea? – John Dec 11 '16 at 12:41
  • 1
    Your mean that the exception is thrown inside of the logger? That seems unlikely – Kevin Gosse Dec 11 '16 at 12:43
  • @KevinGosse The logger didn't log anything or something but has thrown an exception containing the details of the original problem. What I want is a logger that acutally logs things and does NOT throw exceptions. :/ – John Dec 11 '16 at 12:57

0 Answers0