- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Logically, it's a disjoint union of the type of the errors and the type of the ordinary results. I don't know how you express that in Go, but it'd be trivial in Haskell or one of the other functional programming languages.
Admin
I disagree. If it is an emergency the application should exit. The point of raising exceptions is that we hope the consumer may know a way to to handle the situation. Of course the exceptions must be caught as early as possible, to handle the situation.
If exceptions are well documented, I will know that
make_file
may throwOSError
if the path does not exist. Now my application may expect that the path may not exist, so I can catch onlyOSError
and try to firstmkdir("some/log/path", recursive=True)
then callmake_file
again. If I get an unexpected exception, that will result in application getting killed with a nice stack trace.Admin
Now I do not! that seems like a weird language.
Admin
Strictly, they should be caught at the point that knows how to handle the exceptional situation. What point is that? It depends on the application. Sometimes the right way to handle it is to just use the next filename from the list. Sometimes the right way is to show a dialog box to the user. Sometimes it is to write a frantic message to the log and bomb the whole OS out. (I hope I don't hit that last one often, but if the hardware is up the spout, that's probably for the best; a failing motherboard is very bad news.)
Admin
Except that you can return an error as well as a valid result, such as when you're reading from a socket and the socket gets cut off halfway through the read. You still return the number of bytes read, but you also return an error.
Admin
That depends on how you're modelling the failure mode, of course…
Admin
I have a serious question. In a language with checked exceptions, what happens when the called method (in a updated version) adds a new exception? Is that correctly considered a breaking change, like, for every single app? Or just apps start crashing when they didn't used to?