26
u/Svizel_pritula Jan 10 '20
How many methods throw an exception during normal operation?
75
u/pine_ary Jan 10 '20
Every single one? How else do you return a value? Exception-oriented programming is where it‘s at.
30
u/Svizel_pritula Jan 10 '20
That's too much boilerplate. Just send info to the parent method via a TCP socket.
22
6
5
4
u/Retro_RL Jan 10 '20
Let's just replace booleans/switches and instead throw a different exception for each condition
11
u/TheUnlocked Jan 10 '20
All the time. Many exceptions are the intended result of normal operations, for example an IO error from another process holding a lock on a file that you want to access. Exceptions as a form of control can also be useful in certain situations for passing information down the stack, for example a halt message.
9
Jan 10 '20
Different question, then: how many methods throw an Exception, i.e. the default exception class?
9
3
1
5
u/EquationTAKEN Jan 11 '20
The init part is strictly unnecessary. But the @throws tag is actually useful if you're auto-generatic docs for this later.
The biggest contention I have is; don't throw a generic exception. Preferably, you should have various exception classes that are a bit more informative than the generic one. Self-documenting, if you will.
7
3
2
1
153
u/sendvo Jan 10 '20
thanks for reminding me how much i hate comments like this
return id; // returns an ID