+ 3

Are you irked that Java can't figure out what exceptions are thrown simply from the "throw" statements in the block, and so requires the use of "throws" declarations?

Yeah me too. /snark

3rd Aug 2016, 10:25 PM
Andrew Sadavoy
Andrew Sadavoy - avatar
7 Respuestas
+ 1
The key to programming, is knowing when something might throw an exception and coding based off that knowledge. Otherwise, you're essentially blindly letting your code do run.
4th Aug 2016, 12:01 AM
James
James - avatar
+ 1
@James I understand the utility of explicit "throws" declarations to method clients when the throw is implicit i.e. resulting from some operation like a div by zero or null ref. My point is that using an explicit "throw" statement is a pretty clear indication to the compiler that an exception is possible i.e. it *implies* the "throws" statement. In my humble opinion, the compiler ought to be able to provide the "throws" information to clients in such cases (other languages do this). I just find it a little annoying is all. I'm sure I'll get over it. 😀
4th Aug 2016, 12:35 AM
Andrew Sadavoy
Andrew Sadavoy - avatar
+ 1
Never played with another language that did what you're saying, so don't have that gripe yet :) and I just realized what you meant in your original grunt so my response was off base there. My bad. gripe away :D
4th Aug 2016, 12:43 AM
James
James - avatar
+ 1
Actually... If someone else writes code that uses that method, it gives them an indication of what exception it might throw, without them having to read the code. So a good thing for reusability and maintenance.
7th Jan 2017, 7:18 PM
ifl
ifl - avatar
0
I suppose that it makes the code cleaner and more maintainable. You know while reading the code which methods may throw an exception and when it is catched,without reading the whole methods
5th Aug 2016, 11:24 PM
Alberto Brandolini
Alberto Brandolini - avatar
0
hai bro my name is hendra from indonesia
8th Dec 2016, 3:24 AM
Hendra Lie
Hendra Lie - avatar
0
i love java programming leangue SE, EE or android
8th Dec 2016, 3:25 AM
Hendra Lie
Hendra Lie - avatar