Re:Java’s Checked Exceptions Are Evil? (2015)
by leothekim on Sunday September 23, 2018 @09:42AM
(#18051040)
Nothing about checked exceptions inherently prevents the failure scenarios you list, particularly the one about the power failure.
Re:Java’s Checked Exceptions Are Evil? (2015)
by hyperman1 on Sunday September 23, 2018 @10:35AM
(#18051248)
Correct, this was about swallowing errors instead of rethrowing/handling.
Checked exceptions are good if you want to be sure your caller does something when things go south. Some examples from my experience:
* Most things that should be told to the end user, i.e. Business Exceptions. E.g. a webshop user tries to buy something but your stock has been emptied why he was deciding if he should buy or not.
* Follow-up after a modification: If you wrote half a file, you can delete it in your catch IOException instead of letting it linger around. My company has a tendency to pick up and process any file found in an output directory as soon as you release the file lock. But just not filling your disk is good enough for me as reason.
Re:Java’s Checked Exceptions Are Evil? (2015)
by leothekim on Sunday September 23, 2018 @09:46AM
(#18051058)
Also, I gave a bad example for empty try catch. In this case, I would want a runtime exception thrown. Apologies for misleading the conversation.
For example: you store a conversion factor in you config file (eurostodollars=1.12 or whatever).
If you have an empty catch block, you now have a null Reader object or something. Next read will throw an IOException, which you also swallow and you now have an uninitialized config value. Except that one will be zero instead of null.
500 km further in your code, a month after you started the app, that zero gets used in your code.
This will not fail immediately either. No, it will do something weird. In the best case, you crash for a really weird reason. More probably, you send out a file or web call or ... with insanely wrong data. Bonus points if you sign it with a private key, then you're legally bound by whatever nonsense you happened to promise. The next program in the chain might sit either in your company or not. It will swallow your garbage date wholly, do no checking of its own as this no-error-checking culture is pervasive. It will either crash and or do further damage. When the shit finally hits the fan, it will be a containerload of shit instead of a mouse dropping.I saw this kind of scenario again and again. No , the app cant possibly start without database, that never happens, and anyway the next user will notice the empty database. Except after power failure in the middle of the night, when the database is still booting up while your app is reading the config from it. When business hour start, everything seems fine. Until it isnt.