Skip to main content
GameDev.net gamedev.net
🔒 Locked

Question on Exceptions

Started by GameDev.net Mar 2, 2012 at 6:12 PM 0 replies 1.8k views
Original Post
GameDev.net
GameDev.net
Hi,

I nearly never used Exceptions in my Programs until now (well, it worked fine until nowwink.png ),
but I wonder, wether this may be (very?) bad coding style and wether I will get problems when my Project meets a certain size...

Basically my question is:
Are Exceptions in Java a "must-have" to simplify debugging and have clean code or are they just to have decent code (and are not that important)?

thx in advance
haegarr
haegarr
On the one hand they are important because each and every library throws exceptions, including the Java runtime library. So you have to deal with them. On the other hand there is a never ending discussion whether exceptions should be used as a general failure notification system or else just if programming errors are found. In the latter case you are required to check every eventuality before invoking a routine, while in the former case you rely on the checks being performed inside the routine. (Notice that there is also a small fraction that speaks of exceptions as a kind of more or less regular return mechanism, but that is widely seen as a serious misuse.)

That said, you can write programs that do not throw exceptions in own code, but you ever should handle exceptions possibly being thrown by 3rd party code. E.g. libraries that deal with files, networking, or similar stuff are ever good for throwing the one or other exception.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.