Skip to main content
23 events
when toggle format what by license comment
May 21, 2019 at 8:53 comment added David Arno @Caleth, that does seem to be the problem with my answer. "... many frameworks, including Java and .NET, will throw exceptions for the most trivial of reasons, such as a file not existing when trying to open it" directly refers to exogenous exceptions but that's clearly not obvious as everyone seems to miss it. What I meant and what people read are clearly very different here. Just as TryParse is a better solution than throwing exceptions, so TryFileOpen would have been a better solution. But it doesn't exist, so those exogenous exceptions become vexing exceptions that we must handle.
May 21, 2019 at 8:44 comment added Caleth What you were missing is that there are exogenous exceptions, in addition to vexing exceptions. Those don't have to bring down the whole system, and often aren't worth coding around, e.g. if they come from the platform or a library.
May 21, 2019 at 7:14 comment added David Arno @NickAlexeev, thanks for the link. This answer is beyond salvaging, but for next time a similar question comes up, I'll know to call them "vexing exceptions" rather than trivial ones and link to that post in support. At least I can take comfort here from knowing that my views match those of Eric Lippert, even if they are so out of kilter with folk here.
May 21, 2019 at 1:08 comment added Nick Alexeev classic blog post by Eric Lippert: Vexing Exceptions
May 20, 2019 at 19:40 comment added Delioth 1) Catch-all-and-swallow isn't really a popular pattern, it's one of the generally-taught bad practices. 2) Exceptions aren't necessarily something going "seriously wrong", but more of something being exceptional and different from the expected flow - you must admit that there are exceptional cases that aren't serious errors. If I look for a file and it's not there, that's an exceptional case that I can handle in many ways depending on context (try again in a minute, ask the database for info, ask the user, crash)... but it's not unrecoverable.
May 20, 2019 at 19:17 comment added David Arno @whatsisname, I refer you to my previous reply: it's the try pattern, eg I might have a bool TryOpenFile(out Stream stream) if I'm using a language without discriminated unions. If I have the benefit of DUs, then I can return a Stream or some error type asrequired.
May 20, 2019 at 19:01 comment added whatsisname So if attempting to open a non-existent file shouldn't throw an exception, what is your superior alternative?
May 20, 2019 at 17:27 comment added David Arno @RobertHarvey, sure. But as eg the try pattern grows in popularity, so more people stop forming the current and start swimming too. Over time, the swim becomes ever easier until only the diehards are left opposing the "new" idea.
May 20, 2019 at 17:07 history edited David Arno CC BY-SA 4.0
deleted 82 characters in body
May 20, 2019 at 16:51 comment added gaazkam In that case: Might I ask why should exceptions be only thrown when the system must crash?
May 20, 2019 at 15:19 comment added Robert Harvey @DavidArno: While I also tend to be a contrarian, the manner in which exceptions are properly used is well-understood and unremarkable. In languages that use them, I suppose you could create your own error code system instead, but that would be swimming against a really strong current.
May 20, 2019 at 15:16 comment added David Arno @RobertHarvey, a few years ago, if I posted an answer that criticised inheritance for example, I’d have got heavily downvoted. These days, folk have caught up with that idea and I get upvotes. The same has happened to me with unit tests not being a test of a single method/class and numerous ideas on functional programming. Clearly my ideas on exceptions are a bit too progressive for folk here, today. Shrug.
May 20, 2019 at 14:43 comment added Robert Harvey I (and apparently a few other people here) am inclined to agree with Michael. There's nothing that a program can do about a file that does not exist except ask for a new file name. Sensible programs might check to see if the file exists first before attempting to open it, but if your framework has a function in it whose sole purpose is to open a file, and you provide it with a file name that doesn't exist, the only sensible thing to do is throw and allow the client to catch.
May 20, 2019 at 14:31 comment added David Arno @Caleth, resulting in some abstracted StatePersister class that just called state = persistance.Load() receiving a FileNotFoundException and thus having a choice: crash the app or just catch all exceptions and display a useless "Can't load your save data" message to the user. "Exceptions also allow for arbitrary amounts of stack unwinding..." sounds so good, but it is rarely useful in practice.
May 20, 2019 at 14:24 comment added Caleth Yes, but the immediate caller of File.Open(...) probably doesn't have the context to know what to do in the face of that. Exceptions also allow for arbitrary amounts of stack unwinding, without having to lift all the intervening code
May 20, 2019 at 14:17 comment added David Arno @Caleth, There is nothing exceptional about a file not existing. It's a perfectly normal result of trying to open a file.
May 20, 2019 at 14:14 comment added Caleth Insisting that "a file not existing when trying to open it" isn't exceptional, in all circumstances, including it having existed microseconds earlier, seems rather naive.
May 20, 2019 at 14:12 comment added David Arno @MichaelBorgwardt, you are entitled to your opinion.
May 20, 2019 at 14:11 comment added Michael Borgwardt Well, then you are wrong on both counts.
May 20, 2019 at 14:11 comment added David Arno @MichaelBorgwardt, unsurprisingly, I completely disagree with you on both counts.
May 20, 2019 at 14:09 comment added Michael Borgwardt That something has gone seriously wrong does not mean the program should crash. And trying to open a file that does not exist is not a "trivial reason". It is a very good example for where an exception is appropriate.
May 20, 2019 at 14:04 history edited David Arno CC BY-SA 4.0
added 2 characters in body
May 20, 2019 at 13:59 history answered David Arno CC BY-SA 4.0