3 ms·
And that's why I never (or very rarely) put "this should never happen" exceptions anymore in my code Because you eventually figure out that, yes, it does happe
by raverbashing 3y ago
And that's why I never (or very rarely) put "this should never happen" exceptions anymore in my code
Because you eventually figure out that, yes, it does happen
- airstrike 3y agoThis here is the true takeaway. The bar for writing "this should never happen" code must be set so impossibly high that it might as well be translated into "'this should never happen' should never happen"
- andrewaylett 3y agoThe problem with that is that most programming languages aren't sufficiently expressive to be able to recognise that, say, only a subset of switch cases are actually valid, the others having been already ruled out. It's sometimes possible to re-architect to avoid many of this kind of issue, but not always. What you're often led to is "if this happens, there's a bug in the code elsewhere" code. It's really hard to know what to do in that situation, other than terminate whatever unit of work you were trying to complete: the only thing you know for sure is that the software doesn't accurately model reality. In this story, there obviously was a bug in the code. And the broken algorithm shouldn't have passed review. But even so, the safety critical aspect of the complete system wasn't compromised, and that part worked as specified -- I suspect the system behaviour under error conditions was mandated, and I dread to think what might have happened if the developers (the company, not individuals) were allowed to actually assume errors wouldn't happen and let the system continue unchecked.
- pmontra 3y agoA customer of mine is adamant in their resolve to log errors, retry a few times, give up and go on with the next item to process. That would have grounded only the plane with the flight plan that the UK system could not process. Still a bug but with less effects to all the continent, because planes that could not get inside or outside the UK could not fly and that affected all of Europe and possibly more.
- crabbone 3y ago> That would have grounded only the plane with the flight plan that the UK system could not process. By the looks of it, it was few hours in the air by the time the system had a breakdown. Considering it didn't know what the problem was, it seems appropriate that it shut down. No planes collided, so the worst didn't happen.
- pmontra 3y agoCouldn't the outcome be "access to the UK airspace denied" only for that flight? It would have checked with an ATC and possibly landed somewhere before approaching the UK. In the case of a problem with all flights, the outcome would have been the same they eventually had. Of course I have no idea if that would be a reasonable failure mode.
- PeterStuer 3y agoSo what does your code do when you did not handle the this should never happen exception? Exit and print out a stacktrace to stdout?