Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As a general rule, I would say strive to <strong>log all the information necessary to reproduce the course of events leading to an error</strong>. Note that you don't necessarily need to log everything inside the <code>catch</code> block: you can put (debug) log statements around in your code, inside methods called etc. which enable you to follow what was going on directly before the exception. Also, you should put information into the exception itself about the exact symptom what caused it.</p> <p>IMHO going through all the code to add log statements everywhere may be overkill - or at the least, not cost effective in a real life project. Instead, <strong>focus on the most critical code parts</strong> to maximize returns from your efforts. These code parts are typically where the most bugs happen and/or the most modifications are (going to be) done. So in practice whenever you need to touch a piece of code, think about logging, check the log statements already present there (if there is any), check exception handling (if there is any - I routinely see not only code like your example which simply swallows the exception caught, but even empty or autogenerated <code>catch</code> blocks in our legacy code... all of these may leave the application in undefined state, which is a BAD THING), and think about whether what is already there is enough for you to reproduce failures and understand what happened if an error occurs. Then improve it as much as you need to and can with a reasonable effort.</p> <p>It also helps to discuss this topic with your teammates and try to <strong>work out a rough project convention</strong> of how to log events, how to handle exceptions etc. This might save you a lot of time otherwise spent on chasing bugs and/or improving code produced by your very coworkers :-(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload