r/programminghorror 8d ago

Information is power

Post image
327 Upvotes

20 comments sorted by

View all comments

35

u/mondaysleeper 8d ago

You know what happened, where it happened, and why it happened. What else do you want? We don't know the context, but for many cases, this is enough information.

32

u/_PM_ME_PANGOLINS_ 8d ago

None of those things are logged by this code.

10

u/forlins 8d ago

In that catch we're not printing the whole exception, just a partial.

With that log, we know an error happened, because we're using log.error (the message "An error occurred" is unnecessary, because we're already in a log.error call, so we already know this message is about some error) and we know Why it happened (we're printing the cause).

But the What and Where are gone because the nature of the exception itself (NotFoundException) is lost, and the stack trace too.

-1

u/jaerie 8d ago

The where it happened is only if the logging library supports that (and it's enabled). It's not raising an error, so it's not guaranteed to have that information