none
Get more info on exceptions? RRS feed

  • Question

  • Hi,

    In the past I had this a few times with different types of errors.
    For example: on a user machine the .NET application crashes.
    I look in the event viewer and see FileNotFoundException, but it doesn't say which file!!! :-(

    The only way I know to find it, is to attach a debugger or have visual studio...
    But you can't expect a user to have this can you and certainly if the file was a simple shared file.

    Another workaround is by using FileMon from Sysinternals, but this doesn't cover other types of errors that miss crucial info.
    I can't imagine that Microsoft hasn't addressed this by now.

    Am I the only one complaining about this error or is there a more easier way to see this?

    Thanks,
    Jeroen
    Monday, May 4, 2009 10:11 AM

All replies

  • The Watson crash event doesn't have many usable details.  Write an AppDomain.UnhandledException event handler and log the exception details.

    Hans Passant.
    Monday, May 4, 2009 10:59 AM
    Moderator
  • Thanks Hans,

    I was hoping that this wasn't needed.

    In case of a missing file I would assume that it logs it (which it does) but then at least with the filename. It just seems so unlogical/user unfriendly that it gives an error that a file isn't found without saying which one...
    • Marked as answer by Marco Zhou Wednesday, May 6, 2009 6:16 AM
    • Unmarked as answer by Marco Zhou Wednesday, May 6, 2009 6:16 AM
    Monday, May 4, 2009 1:33 PM
  • The FileNotFoundException has a FileName property
    http://msdn.microsoft.com/en-us/library/system.io.filenotfoundexception_members.aspx

    Log that and you'll have the file that it was looking for.
    • Marked as answer by Marco Zhou Wednesday, May 6, 2009 6:16 AM
    • Unmarked as answer by nobugzModerator Wednesday, May 6, 2009 9:26 AM
    Monday, May 4, 2009 8:25 PM
  • Yes, that's true.
    But that's the problem... It's not when an error occurs caused by my application.
    But due to an external problem, e.g a crucial assembly that is missing because of problems with the setup of the application.
    Then you get this error, even before the application loads.

    Another thing is that when no SDK/... is installed, the messagebox showing the error is even more confusing and gives even less information.

    But ok, I guess it's me then ;-)
    Tuesday, May 5, 2009 10:30 AM
  • Write an unhandled exception event handler as suggested, but log two things (if you really want all the detail and aren't worried about any possible security issues as a result);

    1. ExceptionObject.ToString() - the ToString method automatically includes a bunch of useful data including the error message AND stack trace (with line number if possible etc). Note : It would have been nice if on the FileNotFoundException object they had overridden ToString and included the file name property, but they didn't.

    2.  Every value from the ExceptionObject.Keys and ExceptionObject.Values properties, this should include all the additional information about an error such as file name, queue name, permission name etc. regardless of what type of exception it is... but this still requires that whoever wrote the exception to have done the right thing and used these properties to store the extra detail. This should be the case with built in .net exceptions, but may not be so with custom ones.

    An alternative may be to build your own exception classes inheriting from the existing ones and then override the ToString() and/or Message properties to include the extra data, but that means building a new exception class for every exception you throw and will only work for exceptions where you throw them yourself, so it's not really a great answer.
    Monday, June 22, 2009 4:39 AM