c# - Framework code: Fail silently or throw exceptions -


say have method exists in library/framework, want know if methods should throw exceptions or fail silently; example:

void performaction(item item) {     // throws nullreferenceexception if item null     item.dothis(); }  void performaction(item item) {     //fails silently     if(item != null)     {         item.dothis();     } } 

which solution better - or bit of subjective question?

as stated others, may subjective, , may dependent on context , situation. general rule though, think throwing far preferable option.


i simple analogy; naïve may be, makes clear , valid point:

boss: hey joe, me favor , run down accounting , deliver these important documents there me?
joe: sure, no problem.

joe goes down accounting, finds door locked, , out lunch

possible follow-up #1:

joe returns boss: sorry, office closed. can try again later if want me to, or perhaps have other option getting documents delivered?

possible follow-up #2:

joe realises can't complete task, drops documents in garbage collect.. um.. trash container, , calls day.

which option prefer if boss?


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -