Article:
 |
|
What I Hate About Your Programming Language
|
| Subject: |
|
Java + Exceptions |
| Date: |
|
2003-05-15 16:42:08 |
| From: |
|
anonymous2
|
Response to: Java + Exceptions
|
|
Why would you open a file for reading if you don't think it is going to be there?
If you ask to open a file and it does not exist then, yes, it is an exceptional condition.
Also if you wrote the code in, say, C and you didn't check the return of fopen you would "need" to put a comment to make the intent clear. Why put a comment that can easily be wrong after modifying the code if the compiler can do it for free?
Also if you open a file AND it doesn't exist you would need to check that the return value was not null... messy boilerplate code that is easy to get wrong and hides the logic of the program.
Please give a clear, concise, somewhat complete example of what you are saying you want - to open a file that may/may not exist and have it be fine either way AND detail what you would rather go through than deal with exceptions.
|
Showing messages 1 through 1 of 1.
-
Java + Exceptions
2003-05-15 22:25:54
anonymous2
[View]
Basically the switch stops any (or most) errors from percolating from the system into your function. Some systems are very explicit with their messages so I may have to catch say 20 exception messages to have the function 'continu'.
Another ''envvar'' may later be tested if something went wrong indeed if you want to - and did not reuse that ''envvar''.
So if I open a file - which can go wrong for maybe a hundred reasons with a dozen error codes on this system - a can flick the switch and later test whether it was successful or not - which is the only thing I am interested in. (In this case I am still handling the exception, I know.)
This is obviously not Java, but it makes me understand the question.