Skip to main content

All Questions

1 vote
5 answers
210 views

End method in normal flow versus exception flow

Consider the two following examples: public Something fetchSomething(String key) { if(somethingsMap.containsKey(key)) { return somethingsMap.get(key); } throw new ...
steros's user avatar
  • 121
10 votes
8 answers
2k views

When are try/exceptions not an anti-pattern?

I just finished a discussion with colleagues regarding the use of exceptions in code. Here is the code (pseudocode) that they had written: resp = fetch(URL) if resp.status_code != 200: return ...
Daniel's user avatar
  • 517
33 votes
3 answers
5k views

Error handling considerations

The problem: Since long time, I am worried about the exceptions mechanism, because I feel it does not really resolve what it should. CLAIM: There are long debates outside about this topic, and most ...
Adrian Maire's user avatar
3 votes
2 answers
2k views

Augment a thrown exception with some contextual information

The application this question is about is basically a transpiler which contains a lot of logic. The transpiler is written in C++ (which should not be much of relevance for this question), and it ...
leemes's user avatar
  • 139
26 votes
6 answers
7k views

Why use Either over (checked) Exception?

Not too long ago I started using Scala instead of Java. Part of the "conversion" process between the languages for me was learning to use Eithers instead of (checked) Exceptions. I've been coding this ...
Eyal Roth's user avatar
  • 623
2 votes
3 answers
764 views

Why do assertions in Java need to get enabled?

I really like the concept of assertions in Java in the way how to use them. It's much easier than to write an if and then throw an Exception/Error. But the thing I don't understand is, why do they ...
piegames's user avatar
  • 261
-3 votes
2 answers
1k views

Why ever use exception throw (in C#) except for Class Library development? [duplicate]

Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change). To be more specific, ...
Uri Abramson's user avatar
0 votes
1 answer
123 views

Return values and exceptions [closed]

I wrote simple function that returns a string depending on which condition is TRUE. Here is my code: private String getMyString() { if(!mStrigMember.isEmpty()) { return mStrigMember; }...
user3291059's user avatar
34 votes
8 answers
15k 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'...
Konrad Morawski's user avatar
2 votes
1 answer
186 views

RefactorException: Good idea or bad idea?

When I'm doing large scale refactors I'm often commenting out the contents of methods and using NotImplementedExceptions for stuff that I still need to refactor. Problem is that this is interfering ...
Dirk Boer's user avatar
  • 454
0 votes
6 answers
1k 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 "...
Praxeolitic's user avatar
  • 1,674
34 votes
5 answers
55k views

Throwing an exception inside finally

Static code analyzers like Fortify "complain" when an exception might be thrown inside a finally block, saying that Using a throw statement inside a finally block breaks the logical progression ...
superM's user avatar
  • 7,373
9 votes
2 answers
578 views

Use an else after exception (or not)

Consider this bit of code: if (x == 1) { throw "no good; aborting" ; } [... more code ...] Now consider this code: if (x == 1) { throw "no good; aborting" ; } else { [... more code ...] } The ...
rlandster's user avatar
  • 999

15 30 50 per page