Should one log success of an operation within a try-catch-block, or after it?
Example:
try
do x
log('successful')
catch
log('fail')
end
or is this better:
try
do x
catch
log('fail')
end
log('successful')
I would say that a logger should never fail, but what if, for some reason, it does anyway?
In this specific case, I had a logfile on a network drive which disconnected due to actions of do(x), which however did not fail -- obviously my try failed, but my operation worked. However, I find the latter example harder to read, and I try to keep my code as tight as possible for readability.
try
andcatch
blocks should be as concise and focused as possible.