Arguments for or against using Try/Catch as logical operators
Posted
by
James P. Wright
on Programmers
See other posts from Programmers
or by James P. Wright
Published on 2011-09-12T18:30:44Z
Indexed on
2012/10/23
5:26 UTC
Read the original article
Hit count: 271
error-handling
|programming-logic
I just discovered some lovely code in our companies app that uses Try-Catch blocks as logical operators.
Meaning, "do some code, if that throws this error, do this code, but if that throws this error do this 3rd thing instead".
It uses "Finally" as the "else" statement it appears.
I know that this is wrong inherently, but before I go picking a fight I was hoping for some well thought out arguments.
And hey, if you have arguments FOR the use of Try-Catch in this manner, please do tell.
EDIT
For any who are wondering, the language is C# and the code in question is about 30+ lines and is looking for specific exceptions, it is not handling ALL exceptions.
© Programmers or respective owner