Re: Try/Catch

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

The best value is the correct value that the programmer intended. If try/catch can magically know what that is then Great!

The reason that it knows that is because the programmer has to explicitly set the value in the catch statement - there's no magic to it.

Spock said...

But that just begs the question of why the programmer didn't correct the logic error that led to the exception being raised in the first place!

Err - http://en.wikipedia.org/wiki/Begging_the_question

I'm going to rewrite that as:

said...

But that just asks the question of why the programmer didn't correct the logic error that led to the exception being raised in the first place!

Probably for the same reasons that some callers of open() check the return value to see if it's -1, instead of trying to prove that the file exists and permission to read it is granted before calling open() and then gets().

Spock said...

"they all share the same problem" - not stated what this is

The problem is that whatever value that ends up in the variable, it's not obvious that the variable has now been set to this. It's also not necessarily obvious that this happened at all (that the variable got a "default" value instead of having the operation be successful and getting a real value back).

Spock said...

"whereas, try/catch doesn't" - not stated how this is any better

This doesn't have the issue because one generally sets the variable explicitly in this case. Also, the flow of execution is deliberately interrupted here, which makes it clearer that something went wrong.

Spock said...

This is just handwaving.

Spock

No, it isn't.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu