Recently, I was studying about throwing our own exceptions and I thought that maybe we can use if-else to check for the “suspicious” code and then deal with it in the if block. In the corresponding else block, we may proceed as if no exception arises..
I know it may be a bit difficult to use an if statement to try catching all the exceptions but it is possible. Plus, I guess it will also be better in terms of memory usage as I have heard that try-catch blocks are very expensive in terms of memory usage.
Actually in old languages there were no
try...catchkeywords and you should always use your own ways to deal with exceptions (yes,if-elsecould be used).But today in languages like Java for example there are pieces of code where you MUST use try/catch because of checked exceptions. So depending on the language and what you are coding you can’t completely stop using
try...catchblocks.http://en.wikipedia.org/wiki/Exception_handling#Checked_exceptions