Architecture \ EZLogger Error Logs - lundeen-bryan/EZLogger_SLN GitHub Wiki
EZLogger Developer Notes: Handling Unexpected Errors Gracefully
Problem: Users See Confusing or Unhelpful Error Messages
In many Office-based applications, when an unexpected error occurs, the user is presented with a generic dialog that says something like "Object reference not set to an instance of an object" or "Index was outside the bounds of the array." This doesn't help them understand what went wrong—or what they should do next. Worse, it doesn't help me, the developer, track down the issue.
Goal: Provide a Friendly, Informative Error Dialog
The EZLogger error dialog is designed to solve this problem. It appears when an exception is caught in the application and provides:
- A plain-English explanation of the error.
- The actual error message and stack trace for me to debug.
- A Copy button so the user can paste the message into an email or bug report.
- An Abort button to safely exit the application.
- An OK button to dismiss the dialog without exiting.
Problem: Errors Are Hard to Reproduce and Track
If a user doesn't tell me exactly what they were doing, and I don’t have any logs, I might never figure out what caused a crash. That's why the error dialog also logs the error details to a central error log file.
Solution: Centralized Logging With Caller Context
When an error is caught, it's passed to LogHelper.LogError
. This logs the following information:
- Timestamp
- Calling method name (automatically captured with
[CallerMemberName]
) - Actual error message
- (Eventually) Full stack trace if needed
The log file path is defined in global_config.json
so it can be updated in production without changing any code.
Problem: It's Not Always Clear Where to Place Try/Catch
Since I don’t know where errors will pop up, I'm taking a pragmatic approach. When I hit an exception during testing, I’ll go back and wrap that specific function with a Try/Catch block. That catch will display the error dialog with the message and log the details.
Example Pattern for Catch Block:
Try
' risky code here
Catch ex As Exception
LogHelper.LogError(ex.Message)
Dim errHost As New ErrorDialogHost(ex.Message)
errHost.ShowDialog()
End Try
Problem: The User Gets Stuck Without a Path Forward
In the legacy VBA version, users sometimes just restarted Word if something went wrong. Now, the Abort button will allow a controlled exit, and the Copy button makes it easy for users to report the issue with full context.
Next Steps:
- Integrate error dialog into commonly-used workflows (PDF export, database write, etc.).
- Revisit areas of legacy VBA logic that used
On Error Resume Next
and replace with proper error handling. - Review and update
LogHelper
to capture stack traces and write to a rotating daily log if needed.
This is all part of making EZLogger a professional-grade tool that respects the user's time and helps me fix issues quickly.