3 ms·
I throw errors (it's appropriate to stop code execution). But I also log it, so I can see it historically, but now I also do a 3rd thing! I invoke a programmab
by tlarkworthy 4y ago
I throw errors (it's appropriate to stop code execution). But I also log it, so I can see it historically, but now I also do a 3rd thing!
I invoke a programmable breakpoint, so that if I happen to be debugging that code, I get the debugger setup where I want it!
Note this is only appropriate for things that should "never" happen.
- Kinrany 4y agoCould you set a single breakpoint for the error logging branch and have it catch all unexpected errors?
- eurasiantiger 4y agoIn many debuggers, there is an option to break on unhandled / handled / all exceptions.
- tlarkworthy 4y agoYeah but that often casts the net too wide and catches expected 3rd party internal logic or catches the exception too high and you lose the local context.
- tlarkworthy 4y agoYes with "debugger" in JS and 'breakpoint()' in Python. It's great! For defensive programming I have a common assert routine which does all of the above