News for hackers. Stuff that matters.
Re:Code Design Decision – Always throw custom exceptions by BrandoElFollito on Monday December 19, 2022 @12:36PM (#34054902)
> You don't know which exceptions will be raised in advance.

> Most of exceptions are unrecoverable (that's why they are called exceptions), the best course of action is to crash, which happens by default.

I prefer to propagate such unknown exceptions to a top-level catch to clanly log that something happened.

I usually have two types of exceptions: the ones I expect at some point (a HTTP call failing for some reason) that I may ("when I have time") group in "known exceptions we should not worry about" and log them as "informational", and exceptions I did not anticipate that I want to log as well, but with a critical level because they were, well, unexpected.

So crashing right when they happen may not be the best strategy.

Re:Code Design Decision – Always throw custom exceptions by sandinmyjoints on Monday December 19, 2022 @12:41PM (#34054969)
I really wish English had different individual words for the concepts "known [problem] we should not worry about" and "[problems] I did not anticipate".
Re:Code Design Decision – Always throw custom exceptions by cduzz on Monday December 19, 2022 @01:52PM (#34055999)
warning (a not fatal thing happened; took too long)

error (a fatal thing I was expecting happened; I couldn't reach the API)

exception (a fatal thing I wasn't expecting happened; the runtime fault handler did a thing named XYZ)

Re:Code Design Decision – Always throw custom exceptions by hbrn on Monday December 19, 2022 @01:56PM (#34056065)
ERROR and WARNING log levels.

Everything goes to ERROR by default, some errors get downgraded to WARNING when you confirm they are not important.

Send ERRORs to Sentry (or whatever you use) and deal with them immediately. Send WARNINGs to your favorite centralized logging solution and deal with them when there's too many.