Exception vs Error - Yash-777/LearnJava GitHub Wiki

public class Throwable implements Serializable

  • public class Exception extends Throwable - Can be handle by the program
  • public class Error extends Throwable - Can't be handle by the program

Exception

checked Exception are checked at compile time.

The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions

Checked exceptions need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

public class IOException extends Exception

un-checked Exception are checked at run time

RuntimeException and its subclasses are unchecked exceptions.

Unchecked exceptions do not need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

« Passed at runtime
public class RuntimeException extends Exception

==============================================================================
com.sun.org.apache.bcel.internal.classfile.ClassFormatException

ClassFormatException extends RuntimeException
==============================================================================	
java.io
	FileNotFoundException extends IOException
	EOFException extends IOException
	
==============================================================================	

java.lang
String passed null and accession methods:
	NullPointerException extends RuntimeException
	
UnModifiable Map:
	UnsupportedOperationException extends RuntimeException
	ConcurrentModificationException

Accessing array with index greter than of its size:
	ArrayIndexOutOfBoundsException extends (IndexOutOfBoundsException extends RuntimeException)
	StringIndexOutOfBoundsException
	ArrayStoreException extends RuntimeException

Buffer get filled need to flush:	
	BufferOverflowException extends RuntimeException
	
On Reflection API - May the class not available in jar OR Unable to Cast
	ClassCastException extends RuntimeException
	ClassNotFoundException extends (ReflectiveOperationException extends Exception)
	NoSuchFieldException
	
value non-ZERO/ZERO
	ArithmeticException extends RuntimeException

Error

VirtualMachineError extends Error

StackOverflowError extends VirtualMachineError
	Thrown when a stack overflow occurs because an application recurses too deeply.
	
OutOfMemoryError extends VirtualMachineError
	Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory,
and no more memory could be made available by the garbage collector.

Heap memory is the run time data area from which the memory for all java class instances and arrays is allocated.
The heap can be of fixed size or variable size depending on the garbage collection strategy. Maximum heap size can
be set using –Xmx option. By default, the maximum heap size is set to 64 MB.

LinkageError extends Error

NoClassDefFoundError extends LinkageError
	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.
	
UnknownError extends (VirtualMachineError extends Error)
ClassCircularityError extends (LinkageError extends Error)
ClassFormatError extends LinkageError
ThreadDeath extends Error
An instance of ThreadDeath is thrown in the victim thread when the (deprecated) Thread.stop() method is invoked.