6 ms·
Visual basic had an "ON ERROR RESUME NEXT" feature, which would simply ignore all exceptions and keep running code. Obviously, when one thing goes wrong in a p
by londons_explore 6y ago
Visual basic had an "ON ERROR RESUME NEXT" feature, which would simply ignore all exceptions and keep running code.
Obviously, when one thing goes wrong in a program, frequently that leads to other things going wrong, but IMO thats better than crashing the whole process.
Sure, you might get unexpected output, but for many usecases, unexpected output is better than no output at all.
- akx 6y agoExcept maybe healthcare or finance or nuclear plant management software...
- perl4ever 6y agoTurning off exceptions in this case doesn't prevent you from handling errors. You just have to check the error object to see.
- the_af 6y agoNo, this is not what the person who mentioned ON ERROR RESUME NEXT is arguing. They are arguing in some cases it's better if the program plods along and produces any output, even wrong output, rather than crashing. I think the post above explains why this isn't the case in mission critical software. I'd argue the lesson from software engineering is that it's not advisable in most situations, not just for nuclear reactors. The error was raised by a reason, after all. I'd say it's the opposite: there are some limited cases where you absolutely know the exception is not relevant, and in those cases you can knowingly swallow the exception.
- perl4ever 6y agoThey stated that the feature "would simply ignore all exceptions". It allows you to ignore all exceptions, but you don't have to and probably wouldn't in most cases. It was an example of blaming a tool for a hypothetical misuse that is not the only way you can use it.
- the_af 6y agoI think the original poster implied one would indeed use it to ignore all exceptions. But also, it's exactly like an empty catch all exceptions block, which is considered a mistake today, for good reason. I'll go an extra mile and say I'm familiar with this construct in Basic, have seen it used, and nobody ever checked any error codes when using it. It's a footgun that's used almost exclusively to shoot at feet.
- alboy 6y agoIsn't it effectively the same thing as swallowing Throwable with an empty catch block in Java?
- londons_explore 6y agoYes, but you need to wrap every line of source code in your whole program (and all libraries) with an empty catch block to have the same result. Just a single top level catch block would prevent other code after the error occurred from running, which might still be able to work fine without the results of the faulty code.
- alboy 6y agoI see. I'm just not sure that situations where this way of exception handling is a viable strategy are common enough to warrant this syntactic sugar (which seems very easy to misuse). The Visual Basic docs also recommend using structured exception handling instead. Perhaps it is more useful in scripting contexts.
- the_af 6y agoThey are not viable strategies, which is why the analogous strategies in modern-day languages are heavily discouraged and wouldn't pass a code review.
- the_af 6y ago> but IMO thats better than crashing the whole process It's not. Crashing the process (if the error remains unhandled at the top level) is the right answer. When the program raises an exception, you want to either handle it or pass it up, not ignore it. It was raised for a reason. Once an error was raised, if the program ignores it and happily continues all bets are off. This is like reasoning out of false premises: everything goes, which is undesirable. Data is probably corrupted, maybe preconditions are unmet. For this reason, most automated code checkers consider ignoring exceptions a serious antipattern.