4 ms·
Lazy developers throw exceptions, good developers return errors. Exceptions should be exceptional. I'll use URL to this bug in my next comment-holywars to prov
by EugeneOZ 7y ago
Lazy developers throw exceptions, good developers return errors. Exceptions should be exceptional.
I'll use URL to this bug in my next comment-holywars to prove this point.
Yes, it takes much less code to throw an exception in hope some code will catch it, but while compiler (not runtime) doesn't check it - this technique is not safe. So we should return errors, check them and handle - sometimes it means returning error further, but in some function we'll write code to handle this case without crashing the system (or, at least, it will shutdown everything gently, without panicking).
- saagarjha 7y agoLazy developers also ignore errors by swallowing them. In this particular case, note that the error was detected many methods away because of Objective-C's weak typing, not because the developers "chose" to throw an exception.
- ec109685 7y agoCrashing a program is often safer for unexpected conditions than hoping your error handling will recover from it? Have you tested every combination of state + error and made sure your app is robust for each situation?
- EugeneOZ 7y ago1) Quite the contrary. And there is no "hope" - you either write code to recover or you throw an exception (and then there is a "hope" that some other code will catch it), it's just different approaches. 2) Yes, it's not so difficult. Writing tests, for example, also takes time - it's not a reason to don't write tests.
- kennywinker 7y agoThis error is due to use of a un type checked language (objc). You can blame the coding style all you want but it’s like blaming bad drivers for accidents instead of fixing the system.
- Buge 7y ago> blaming bad drivers for accidents instead of fixing the system. I had to read that several times before I realized you weren't talking about computer device drivers and computer systems.
- plorkyeran 7y agoYou want to write explicit error handling for every possible case of runtime type errors in a dynamically typed language? The "unrecognized selector sent to instance" exception is not thrown in the hope that someone will catch it. It's intended to be a fatal error reporting a precondition violation.
- aaronbrager 7y agoThat’s what secure coding guidelines say to do. It’s called “input validation”. For example here’s Apple’s: https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/ValidatingInput.html https://developer.apple.com/library/archive/documentation/Se... Especially important on methods called on launch, if a crash would cause a problem. (Swift or other strongly typed language would help here.)
- lagadu 7y agoThe halting problem's existence means that there's no input validation that is guaranteed to work absolutely 100% of the time though, for sufficiently large inputs.
- icebraining 7y agoSeems like a pretty bad example - it only caused a boot loop. That's inconvenient, but fairly minor compared to the myriad of problems that could have arisen from buggy recovery code.