Timeline for When are try/exceptions not an anti-pattern?
Current License: CC BY-SA 4.0
26 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 20, 2023 at 6:50 | comment | added | Kyralessa | Anti-pattern is not a term that really has any meaning, any more than "best practice" does. Both are excuses for people to turn their brains off. Don't accept anyone telling you something is a "best practice" or an "anti-pattern" if they can't explain the reasons why. | |
May 5, 2023 at 17:25 | comment | added | Eric Lippert | The key design question is: is a web site returning a non-200 code an exceptionally unusual behaviour or a normal behaviour? If it is an exceptionally unusual behaviour then use an exception handler. If it is a normal behaviour then use normal conditional logic. Exception handlers are called that because they are for handling exceptionally unlikely situations. | |
May 4, 2023 at 18:29 | answer | added | Karl Bielefeldt | timeline score: 1 | |
May 1, 2023 at 12:14 | answer | added | gnasher729 | timeline score: 0 | |
Apr 30, 2023 at 15:53 | comment | added | greenoldman | @Christophe, thank you. I don't agree with your conclusion though. IMHO if your design and execution cost is similar you should always chose more performant way. Excusing yourself "that in given context it is irrelevant" piles up. | |
Apr 30, 2023 at 8:41 | comment | added | Christophe | See also stackoverflow.com/a/39311200/3723423 for performance impact, and when to use exceptions and when not. | |
Apr 30, 2023 at 8:38 | comment | added | Christophe | @greenoldman with modern C++ compilers, entering a try block has no noticeable performance effect. Throwing is of course more costly due to stack unwinding. This is why exceptions should be use for exceptional cases. -- (I have past measurements of a couple of microseconds for a throw compared to a nanosecond level for a return, but this difference is irrelevant for processing web requests, where you'll work at milisecond level, i.e 1000 times slower than microseconds, and 1000,7 vs 1000,05 will not make the difference) | |
Apr 30, 2023 at 6:25 | comment | added | greenoldman | @Christophe "You'll also find a lot of obsolete remarks about performance issues related to these constructs." Are you saying that nowadays exceptions are performant? | |
Apr 30, 2023 at 6:11 | answer | added | greenoldman | timeline score: 0 | |
Apr 30, 2023 at 2:45 | history | edited | Alexander | CC BY-SA 4.0 |
added 1 character in body
|
Apr 29, 2023 at 19:37 | history | protected | gnat | ||
Apr 29, 2023 at 17:11 | answer | added | Ewan | timeline score: 1 | |
Apr 29, 2023 at 7:17 | answer | added | Ben Cottrell | timeline score: 14 | |
Apr 29, 2023 at 0:14 | answer | added | sglmr | timeline score: -2 | |
Apr 29, 2023 at 0:10 | comment | added | mentallurg | @Daniel: The way how you use try/catch makes no sense. You should not catch exception and return boolean. Instead, the exception should be propagated to the higher layers, e.g. to some controller or some REST service. This is the whole idea of exceptions - to make the code shorter and to focus on whenever possible on the "happy flow" only. | |
Apr 29, 2023 at 0:05 | comment | added | mentallurg | @Daniel: "resources which declare try/except a discouraged pattern" - I don't know any such pattern. Please provide links that explain what you mean. | |
Apr 28, 2023 at 19:57 | answer | added | JacquesB | timeline score: 10 | |
Apr 28, 2023 at 19:26 | review | Close votes | |||
May 3, 2023 at 3:05 | |||||
Apr 28, 2023 at 19:18 | comment | added | Daniel | @Christophe thank you that is helpful! | |
Apr 28, 2023 at 19:18 | comment | added | Christophe | See also here how the exception throwing is exempted to the single exit point rule, including in industrial secure coding standards softwareengineering.stackexchange.com/a/416677/209774 - See here for an anlalysis of the C++good practices softwareengineering.stackexchange.com/a/430994/209774 (in the comments, you'll see a discussion on the performance aspects). | |
Apr 28, 2023 at 19:11 | comment | added | Christophe | @Daniel while there are antipaterns in these constructs, if used for "exceptional" situations, it is a perfectly valid construct. You'll also find a lot of obsolete remarks about performance issues related to these constructs. These date back to the early days of Java and C++ and are no longer relevant. See for example this recommendation: isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Re-errors | |
Apr 28, 2023 at 19:09 | answer | added | Martin Maat | timeline score: -3 | |
Apr 28, 2023 at 18:51 | comment | added | Daniel | @Christophe I found a lot of resources which declare try/except a discouraged pattern in code...which surprised me, I'll admit. Although, it seems that the reasons not to use them have to do with managing control flow unnecessarily | |
Apr 28, 2023 at 18:34 | comment | added | Christophe | When are try/exception an anti-pattern? | |
S Apr 28, 2023 at 17:23 | review | First questions | |||
Apr 28, 2023 at 20:01 | |||||
S Apr 28, 2023 at 17:23 | history | asked | Daniel | CC BY-SA 4.0 |