Labels

Android (1) bash (2) boost (2) C (34) C++ (2) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (1) Dreamweaver (2) Eclipse (3) fail2ban (4) git (5) GitHub (4) Hacking (3) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (30) javascript (3) Linux (164) Mac (19) Machine Learning (1) mySQL (47) Netbeans (4) Networking (1) Nexus (1) OpenVMS (6) Oracle (1) Pandas (3) php (16) Postgresql (8) Python (9) raid (1) RedHat (14) Samba (2) Slackware (45) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (3) Visual Basic (1) Visual Studio (1) Windows (2)

Monday 9 January 2017

Exceptions in Java

ArithmeticException – an instance of this class is thrown when an exceptional arithmetic condition has occurred; for example, when integer division by zero has occurred.

NullPointerException – an instance of this class is thrown when you try to send a message to a reference variable whose value is null; that is, it does not reference an object. (The use of the word ‘pointer’ rather than ‘reference’ is a curiosity of the language, a throwback to C language terminology.)

NumberFormatException – an instance of this class is thrown to indicate that a method that converts a string to one of the numeric types has been passed an argument that does not have the appropriate format.

IndexOutOfBoundsException – an instance of this class is thrown when a program tries to access a string with an index outside the valid limits.





Error and its subclasses are used for serious conditions that a program should not normally attempt to catch (handle). An example is an error arising in the JVM itself (which rarely happens), such as the JVM running out of memory. It is best to let the program terminate.

RuntimeException and its subclasses are used for error conditions that a programmer need not write code to process. (For example, the RuntimeException subclass NullPointerException indicates an attempt to send a message using a null reference value.) In some cases such issues may be recovered from or should be dealt with, but it will need to be decided on an individual basis.

Exception and its subclasses, excluding RuntimeException and its subclasses, are used for conditions that a programmer must write code to deal with in some way.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.