4 ms·
bzzt. depending on the language and the author of the exception-throwing code, the exception will contain information about where the error occurred and what m
by aggieben 18y ago
bzzt. depending on the language and the author of the exception-throwing code, the exception will contain information about where the error occurred and what might have caused it.
- Retric 18y agoTrue, but in the above code such information is not propagated outside of the function. If you want to add that you need to throw another exception inside of the catch block or skip the catch.
- natrius 18y agoWhich is exactly the right thing to do. I don't see the problem.
- Retric 18y agoAt this point, I'm tired of typing the code. Checking for errors after every function call is way too much work Think of what the exception code ends up as in ASM. Basically try transparently wraps system calls with the same type of error handling code as his example. However, if you want to write stable code you need to account for each of these errors anyway. So when your DB connection fails you need to know if it’s a TCP/IP error or a Bad Password etc which means either wrapping each line with its own try catch or decoding the exception within a catch block. Granted, exception handling let’s your write code for the ideal case and avoid crashing when something messes up but as soon as you want to recover from an error without starting over you end up writing the same code anyway. And because the happy path works it’s not obvious just how far you are from high quality code.
- aggieben 18y agoSee my later comment about expected errors versus unexpected ones. Exceptions were never meant to replace good error-handling code.