Exforsys.com
 
Home Certification SCJP
 

SCJP 5 : Chapter 2. Flow Control (Part-5)

 

SCJP 5 : Chapter 2. Flow Control (Part-5)

Recognize situations that will result in any of the following being thrown: ArrayIndexOutOfBoundsException, ClassCastException, IllegalArgumentException, IllegalStateException, NullPointerException, NumberFormatException, AssertionError, ExceptionInInitializerError, StackOverflowError or NoClassDefFoundError. Understand which of these are thrown by the virtual machine and recognize situations in which others should be thrown programatically.

ArrayIndexOutOfBoundsException


Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.


java.lang.Object
.....java.lang.Throwable
..........java.lang.Exception
...............java.lang.RuntimeException
....................java.lang.IndexOutOfBoundsException
.........................java.lang.ArrayIndexOutOfBoundsException


ClassCastException

Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:


Object x = new Integer(0);
System.out.println((String)x);


java.lang.Object
.....java.lang.Throwable
..........java.lang.Exception
...............java.lang.RuntimeException
....................java.lang.ClassCastException


IllegalArgumentException

Thrown to indicate that a method has been passed an illegal or inappropriate argument.


java.lang.Object
.....java.lang.Throwable
..........java.lang.Exception
...............java.lang.RuntimeException
....................java.lang.IllegalArgumentException


IllegalStateException

Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.


java.lang.Object
.....java.lang.Throwable
..........java.lang.Exception
...............java.lang.RuntimeException
....................java.lang.IllegalStateException


NullPointerException

Thrown when an application attempts to use null in a case where an object is required. These include:


  • Calling the instance method of a null object.
  • Accessing or modifying the field of a null object.
  • Taking the length of null as if it were an array.
  • Accessing or modifying the slots of null as if it were an array.
  • Throwing null as if it were a Throwable value.
  • Applications should throw instances of this class to indicate other illegal uses of the null object.

java.lang.Object
.....java.lang.Throwable
..........java.lang.Exception
...............java.lang.RuntimeException
....................java.lang.NullPointerException


NumberFormatException

Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.


java.lang.Object
.....java.lang.Throwable
..........java.lang.Exception
...............java.lang.RuntimeException
....................java.lang.IllegalArgumentException
.........................java.lang.NumberFormatException


AssertionError

Thrown to indicate that an assertion has failed. The seven one-argument public constructors provided by this class ensure that the assertion error returned by the invocation:


new AssertionError(expression)


java.lang.Object
.....java.lang.Throwable
..........java.lang.Error
...............java.lang.AssertionError


ExceptionInInitializerError

Signals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.


As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The "saved throwable object" that may be provided at construction time and accessed via the getException() method is now known as the cause, and may be accessed via the Throwable.getCause() method, as well as the aforementioned "legacy method."


java.lang.Object
.....java.lang.Throwable
..........java.lang.Error
...............java.lang.LinkageError
....................java.lang.ExceptionInInitializerError


StackOverflowError

Thrown when a stack overflow occurs because an application recurses too deeply.


java.lang.Object
.....java.lang.Throwable
..........java.lang.Error
...............java.lang.VirtualMachineError
....................java.lang.StackOverflowError


NoClassDefFoundError

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.


The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.


java.lang.Object
.....java.lang.Throwable
..........java.lang.Error
...............java.lang.LinkageError
....................java.lang.NoClassDefFoundError


______________


Author: Mikalai Zaikin. Please Click Here to visit Authors site for any updates and changes to the study notes.



Read Next: SCJP 5 : Chapter 3. API Contents (Part-1)



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape