Erik Darling shares some tips:
Debugging, like error handling, is a design choice that is fairly easy to make at the outset of writing a stored procedure, and is usually a lot easier to get in there if you do it from the get-go.
The number of times I’ve had to go back and add debugging into something only to introduce debugging bugs is actually a bit tragic.
If you’ve never brought down a system with your monitoring process or introduced bugs via debugging code, you’re not living life to its fullest.