Re: Try/Catch

new topic     » goto parent     » topic index » view thread      » older message » newer message
DerekParnell said...
mattlewis said...

Sometimes crashing is the right thing to do. But if a feature of a big program breaks for some reason (let's assume user input that you didn't anticipate, because that's super common) that doesn't mean the whole thing should die. It might be possible to carry on with other aspects.

User input errors are not exceptions, in my way of thinking. User input ought to be validated a soon as practicable upon entering the application.

Like any entity subject to the laws of physics and mathematics, your users will come up with ways to use your program that you didn't think of. Or maybe some module has an error in it even with handling correct input. It could be yours, it could be someone else's. Consider this:

Suppose you write a library. In all of your public interface, you implement exception handling, and then you return an error to your user instead of crashing or giving them an exception they might or might not be able to handle. When you encounter these, or receive reports from users, you fix the error so something more appropriate happens. Now people who use your code (probably including you!) can use your stuff relatively sure that your code won't crash their program (obviously, C calls, etc., may be exceptions to your exception handling, but you get the idea) if they encounter bugs in your code.

What's bad about this?

You can think up examples where this doesn't or shouldn't apply, but that doesn't invalidate my hypothetical presented above.

DerekParnell said...

Wow! Not only annoying, but an example of where exception handling is pointless. So someone went to the trouble of catching an exception that has no effect on the job you're doing with the application. Clever.

Pointless‽ It stops the program from crashing! There's a module that has an error. Rather than die right there, the rest of the program carries on. Not every situation is like this and should be recovered from, and fail fast is an excellent development paradigm, but saying that all errors should halt the program is sometimes equivalent to hating your users.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu