Exception handling is how developers determine why code is failing. The message of the exception, the location telemetry, and the type of exception are important for determining the exact cause.
When logging an exception, there are several rules that must be followed to ensure that all exceptions thrown are useful.
- Never throw an unhandled exception. Unhandled exceptions cause the entire application to crash.
- Never assign an exception that isn’t being used. This generates unnecessary warnings and can cause problems down the line. Exceptions can be caught and ignored, but in that case, there is no point assigning it to a variable.
- Add meaningful messages to errors that are being logged. This provides developers with location and cause information. The more meaningful the message, the more it can help developers to determine where the exception occurred.
When exceptions are logged, they must be stored somewhere. GreatIdeaz stores exceptions in two primary locations. The first location is a table in the database accessible through the trellispark application. The second location is an external Microsoft Application Insights telemetry client. Both locations store information on the location of the error, the message, a stack trace, the user who caused the error, and the time that the error was caused.