0

Can someone explain why exceptions are a thing in programming?

First things first, I understand the basics of exceptions and that you only want to use them for unexpected situations. Why cant you just plan ahead and make an if statement to handle this unexpected? Exceptions to me just sound like lazy programming fall backs. Could someone give a scenario where an if else statement wouldnt cover for an exception and why?

14th Oct 2018, 6:43 PM
Evan Martine
2 Respostas
0
I found an answer to this. If you have a large application with thousands of lines of code one of the worst design choices is to silently catch everything so that no exceptions ever happen. When something doesn't work as intended (e.g. when a list of data is requested a blank screen is shown) it is an actual nightmare to debug. In contrast, using exceptions and getting the code to "fail fast" lets code break soon after an unintended action happens. When combined with meaningful error messages it is much easier to track down the bug
14th Oct 2018, 7:09 PM
Evan Martine