Skip to content

Instantly share code, notes, and snippets.

@kenorb
Created July 21, 2014 20:26
Show Gist options
  • Save kenorb/bcb1ec3baccaafbd6d9e to your computer and use it in GitHub Desktop.
Save kenorb/bcb1ec3baccaafbd6d9e to your computer and use it in GitHub Desktop.
/*
* ExceptionDemo.java
*
* A process of responding to the occurrence, during computation
* – anomalous or exceptional events requiring special processing.
*
* Clauses of Exception Handling
* 1. try
* Program statements which raised exception should be returning try block.
* 2. catch
* Exception throwned by try block will be handled by the corresponding catch block.
* 3. throw
* To throw the exceptions manually use throw clause.
* 4. throws
* When a method is expected to throw one or more exceptions,
* the method definition should list all the exception mains (by using throws clause).
* 5. finally
* Finally is a special block which will be executed whether the exception is thrown or not.
* Or whether the exception is handler or not.
*
* Usage:
* javac ExceptionDemo.java && java ExceptionDemo
*/
class ExceptionDemo {
public static void main(String args[]) {
int a = 10, b = 0;
System.out.println(a/b); // Any number divided by zero generates run-time exception called arithmetic exception.
System.out.println("Hello world!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment