باید عرض کنم بله وقتی کاربری یافت نشد چه کاری میتوانیم انجام دهیم؟
Errors should be handled via exceptions, but successes shouldn't
مشکلی که در اینجا هست این است که بازگشت null یک کاربر در یک کوئری، یک error نیست؛ یک بازگشت و عملیات موفقیت آمیز است. به همین جهت صدور استثناء برای دریافت آن نباید رخ دهد:
The typical meaning of the word "exception" is an
event that is unexpected rather than part of normal operation; otherwise
people would just say "event"
و اینکه نتیجهی یک متد باید در همان متد به صورت استثناء درنظر گرفته شود، غیرضروری است و این تصمیم گیری باید به عهدهی فراخوان گذاشته شود. گاهی میخواهیم بررسی کنیم کاربری در دیتابیس هست؟ اگر بله، آنرا تکراری ثبت نکنیم. گاهی میخواهیم بررسی کنیم اگر در دیتابیس هست، اطلاعات او را به روز رسانی کنیم. اینکه کوئری مدنظر نال بر میگرداند، تصمیم گیری در مورد اهمیت آن ربطی به آن متد ندارد و صرفا به عهدهی فراخوان است:
Methods should have a way to indicate various kinds of results. Whether
those results are treated as exceptional should depend on the caller.