Linked Questions

2
votes
1answer
438 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
1answer
766 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
1answer
505 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
1answer
156 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 ...
78
votes
10answers
13k 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 ...
34
votes
15answers
33k 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 ...
33
votes
8answers
9k 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'...
12
votes
2answers
5k 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 ...
-2
votes
5answers
8k 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
5answers
681 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 ...
3
votes
5answers
1k 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 ...
8
votes
3answers
915 views

For-if antipattern

I was reading on this blog post about the for-if anti-pattern, and I'm not quite sure I understand why it's an anti-pattern. foreach (string filename in Directory.GetFiles(".")) { if (filename....
0
votes
6answers
697 views

Should we only catch in exceptional circumstances?

Whether error handling by throwing exceptions is good or bad is contentious. Are exceptions as control flow considered a serious antipattern? If so, Why? The common line is that exceptions are for "...
1
vote
6answers
233 views

Use of optional parameter for execute in try block?

I observed a dubious design pattern in some C# code today used in several methods: public void DoSomething(bool safe=true) { if (!safe) DoSomethingDangerous(); else { try { ...
6
votes
2answers
701 views

Is it bad practice to have functions whose sole purpose is to throw errors?

I have the following situation. I'm writing a c++ program where I have a function that checks a custom equivalence of two json objects. If the check fails, I don't want the entire program to stop (...

15 30 50 per page