Tuesday 28 June 2016

Java Tutorial : Java Exception handling (Exception propagation)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=OLqBucdWaVM&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Exception handling (Exception propagation)
Java Tutorial : Java Exception handling (Exception propagation)
ExceptionPropagationDemo.java
public class ExceptionPropagationDemo
{

    public static void main(String[] args)
    {
        ExceptionPropagationDemo exceptionPropagationDemo = new ExceptionPropagationDemo();
        try
        {
            exceptionPropagationDemo.method1();
        }
        catch(Exception exe)
        {
            exe.printStackTrace();
            System.out.println("Exception is handled in main method.");
        }
        System.out.println("Normal flow...");
    }

    public void method1()
    {
        System.out.println("method1() is called.");
        method2();
    }

    public void method2()
    {
        System.out.println("method2() is called.");
        method3();
    }

    public void method3()
    {
        System.out.println("method3() is called.");
        String str = null;
        System.out.println(str.length());
    }

}
Output
method1() is called.
method2() is called.
method3() is called.
java.lang.NullPointerException
    at ExceptionPropagationDemo.method3(ExceptionPropagationDemo.java:35)
    at ExceptionPropagationDemo.method2(ExceptionPropagationDemo.java:28)
    at ExceptionPropagationDemo.method1(ExceptionPropagationDemo.java:22)
    at ExceptionPropagationDemo.main(ExceptionPropagationDemo.java:9)
Exception is handled in main method.
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ExceptionDemo_Exception_Propagation_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ExceptionDemo_Exception_Propagation_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/969ffd88eb34c4fd42d966118b27490392b78865/BasicJava/ExceptionDemo_Exception_Propagation_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment