Skip to content

Instantly share code, notes, and snippets.

@ishanbakshi
Last active July 13, 2016 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishanbakshi/4a3061c7e51b8fd1694ae5332ea54b88 to your computer and use it in GitHub Desktop.
Save ishanbakshi/4a3061c7e51b8fd1694ae5332ea54b88 to your computer and use it in GitHub Desktop.
Sample code to test exception catching in JAVA. This code demonstrates how to build a mapper function to find which user defined exception was thrown.
// this code was tested using java ide from tutorials point
// see the running code on http://goo.gl/1pPhqd
import java.lang.*;
public class SampleExceptionCatching{
public static void main(String []args){
try{
System.out.println("Hello World");
throw new SampleException();
}catch(Exception e){
System.out.println("exceptionCatching = "+e.getClass());
e.printStackTrace();
}
}
}
class SampleException extends Exception{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment