Linked Questions
28 questions linked to/from Are exceptions as control flow considered a serious antipattern? If so, Why?
3
votes
3
answers
2k
views
Is it good practice to use try catch for data validation [duplicate]
In my current development task, I want to validate whether a string is in JSON format or not. When I checked for solutions from resources like StackOverflow I saw many of answers are as below,
try{
...
3
votes
1
answer
1k
views
Is it okay to use exception handling as exit conditions for a method? [duplicate]
So I've been programming for a few years mostly as an amateur/student, and I'm aware of the fact that using exceptions is generally frowned upon when used as a lack of consideration for input and just ...
0
votes
1
answer
2k
views
Can I execute a query in a catch block of try-catch? [duplicate]
I want to confirm the right approach of using try-catch exception handler.
I have written a query in a try block, and if any exception is thrown, it will execute a query in a catch block.
Is this ...
1
vote
1
answer
682
views
Is ok to throw exception in normal code path which eliminate a possible programmer error? [duplicate]
I know that exception should be thrown in exceptional case (e.g. out of memory, programmer error). For these cases, I don't need to worry about performance throwing these exception.
But what happen ...
1
vote
1
answer
170
views
Using exceptions as regular objects [duplicate]
I have views that handle different errors in my application. For example error 404, 403 and such, giving my errors a more user-friendly presentation. By assumption, they get passed in an exception, so ...
0
votes
2
answers
230
views
How to effectively manage a large number of exceptions (I18N problematic) [duplicate]
I'm trying to found the best way to manage Exception for all over my application.
Actually, I've come with two solutions :
Solution 1
One Exception to govern them all.
namespace App\Utils\Exception;
...
107
votes
12
answers
55k
views
Result object vs throwing exceptions
When sending a request to another module and expecting a result, it seems to me there are two ways of dealing with the 'non-happy paths'.
Throw an exception
Return a result object that wraps ...
85
votes
10
answers
17k
views
Exceptions, error codes and discriminated unions
I've recently started a C# programming job, but I've got quite a bit of background in Haskell.
But I understand C# is an object-orientated language, I don't want to force a round peg into a square ...
41
votes
15
answers
50k
views
Arguments for or against using Try/Catch as logical operators [closed]
I just discovered some lovely code in our companies app that uses Try-Catch blocks as logical operators.
Meaning, "do some code, if that throws this error, do this code, but if that throws this error ...
34
votes
8
answers
14k
views
Is throwing an exception an anti-pattern here?
I just had a discussion over a design choice after a code review. I wonder what your opinions are.
There's this Preferences class, which is a bucket for key-value pairs. Null values are legal (that'...
36
votes
4
answers
21k
views
Are exceptions for flow control best practice in Python?
I'm reading "Learning Python" and have come across the following:
User-defined exceptions can also signal nonerror conditions. For
instance, a search routine can be coded to raise an exception ...
22
votes
4
answers
2k
views
Exceptions - "what happened" vs "what to do"
We use exceptions to let the consumer of the code handle unexpected behaviour in a useful way. Usually exceptions are built around "what happened" scenario - like FileNotFound (we were ...
-1
votes
5
answers
16k
views
Differences between `throw` and `throw new` and exactly how exceptions "bubble up" [closed]
Can someone please explain the differences in C# between:
throw
throw new
and exactly how exceptions "bubble up" as I've heard they do?
In my daily job, I've used just try/catch to mostly control ...
1
vote
5
answers
1k
views
Limits of Defensive Programming acknowledging that Exception Handling should be avoided
I've read Defensive Programming vs Exception Handling? and if/else statements or exceptions, but none contain something relevant to what I'm searching for.
Taking into account that exception handling ...
4
votes
6
answers
3k
views
Null checking whilst navigating object hierarchies
I had to implement some code which traversed a small object hierarchy to fetch a value and display it in a TextView object (this is Android / Java). I had to do this 6 times to populate 6 TextViews ...