Reputation
2,502
Top tag
Next privilege 3,000 Rep.
Cast close & reopen votes
Badges
7 13
Newest
 Good Answer
Impact
~29k people reached

10h
comment Is throwing new RuntimeExceptions in unreachable code a bad style?
@Joe23 I added an explicit reference to the library
10h
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
added 190 characters in body
10h
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
added 111 characters in body
12h
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
added 1053 characters in body
13h
comment Is throwing new RuntimeExceptions in unreachable code a bad style?
@Joe23 Thanks for the clarification about static dispatch. About throwing exceptions inside the function: do you mean that the possible error you are describing is a catch block which calls logAndWrap but does nothing with the returned exception? That's interesting. Inside a function that must return a value, the compiler would notice that there is a path with no value being returned, but this is useful for methods which do not return anything. Thanks again.
13h
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
added 54 characters in body
14h
comment Why is 'continue' the keyword for skipping the rest of the loop iteration?
@JohnR.Strohm It seems to appear first in Fortran 90; the Fortran 77 specification does not mention it.
1d
awarded  Good Answer
1d
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
added 23 characters in body
1d
comment Why is 'continue' the keyword for skipping the rest of the loop iteration?
@Nail I looked up a little, BCPL had loop, B had next and C might have introduced continue; there was a continue in FORTRAN, which was simply a no-op used as a target of goto. Fortran used cycle and exit for continue and break. But in the above quote for Pascal, at least the verb continue is used in the way OP expects it to be in english sentences, which shows that continue is not necessarly a misnomer. Also, it contains all the previous keywords I mentioned!
1d
reviewed Approve Is throwing new RuntimeExceptions in unreachable code a bad style?
1d
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
added 470 characters in body
1d
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
deleted 3 characters in body
1d
comment Why is 'continue' the keyword for skipping the rest of the loop iteration?
Continue with next loop cycle
1d
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
deleted 91 characters in body
1d
revised Is throwing new RuntimeExceptions in unreachable code a bad style?
added 1832 characters in body
1d
comment Is throwing new RuntimeExceptions in unreachable code a bad style?
Thanks for the edit. The general case of the rethrow method (for Exception) is full of useless casts. The whole thing is here to convert (and specialize) exceptions: it makes even more sense to return exceptions instead of throwing them.
1d
comment Is throwing new RuntimeExceptions in unreachable code a bad style?
@jpmc26 The core of the question is about the "cannot reach here" exception, which could arise for other reasons aside from the preceding try/catch block. But I agree that the block smells fishy, and if this answer was more carefully worded originally, it would have gained much more upvotes (I didn't downvote, btw). The last edit is good.
2d
comment Is throwing new RuntimeExceptions in unreachable code a bad style?
It's as-if you see no issue discarding a whole part of the logic. Your version clearly does not do the same thing as the original, which by the way, already fails fast and loudly. I'd prefer to write catch-free methods like the one in your answer, but when working with existing code, we should not break contracts with other working parts. It might be that what is done in rethrow is useless (and this is not the point here), but you can't just get rid of code you don't like and say it is equivalent as the original when it is clearly not. There are side-effects in the custom rethrow function.
2d
awarded  Nice Answer