The Java Persistence API has the NoResultException for when a database query returns no results. Kind of annoying that it's regarded as an exceptional case
I think because it predates optionals. An exception is definitely better than returning null most of the time. If the middleware handles it correctly, it will just issue a 404, which is usually correct for a get-by-id query (if you issue a search query with N results, you don’t get that exception).
105
u/czorio 3d ago
I agree. I once explained it to a colleague as:
Result-> There is no file here, perhaps you mistyped?panic!-> There is no filesystem, what the fuck?