c# - Try-Catch Exception abuse -
i have found code this:
try { myclass.do().tostring(); } catch () { }
which results in exception being thrown when do()
returns null
. could, instead, use
(myclass.do() ?? "").tostring();
to avoid exception being thrown. see code this:
for (int = 0; < x.length; i++) { if (x.phases[i].num == activenum) { try { result = x.phases[i + 1].obj; } catch (exception ex) { } } }
i think not practice. however, can't find references support ideas.
i tried search on web, did not have luck. of references or documentation meant c++ or java.
will please me justify idea strong reference, or enlighten me if previous approaches above in fact acceptable.
you're correct: using exceptions purposes of flow control bad practice. referred anti-pattern reason.
you can find detailed explanation here. while article references java , c++, anti-pattern in c# same reasons.
for c#/.net specific explanation, see msdn article.
Comments
Post a Comment