Tuesday 28 June 2016

Java Tutorial : Java Exception handling (Exception in detail)


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

Click the below Image to Enlarge
Java Tutorial : Java Exception handling (Exception in detail) 
Java Tutorial : Java Exception handling (Exception in detail) 
Java Tutorial : Java Exception handling (Exception in detail) 
Java Tutorial : Java Exception handling (Exception in detail) 
Java Tutorial : Java Exception handling (Exception in detail) 
Java Tutorial : Java Exception handling (Exception in detail) 
Java Tutorial : Java Exception handling (Exception in detail) 
Java Tutorial : Java Exception handling (Exception in detail) 
ExceptionPropagationDemo1.java
public class ExceptionPropagationDemo1
{

    public static void main(String[] args)
    {
        ExceptionPropagationDemo1 exceptionPropagationDemo1 = new ExceptionPropagationDemo1();
        exceptionPropagationDemo1.method1();
        System.out.println("Normal flow.");
    }

    public void method1()
    {
        System.out.println("method1() is called.");
        try
        {
            method2();
        }
        catch(NullPointerException nullPointerException)
        {
            nullPointerException.printStackTrace();
            System.out.println("Exception handled in method1().");
        }
        System.out.println("method1 completed.");
        
    }

    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 ExceptionPropagationDemo1.method3(ExceptionPropagationDemo1.java:37)
    at ExceptionPropagationDemo1.method2(ExceptionPropagationDemo1.java:30)
    at ExceptionPropagationDemo1.method1(ExceptionPropagationDemo1.java:16)
    at ExceptionPropagationDemo1.main(ExceptionPropagationDemo1.java:7)
Exception handled in method1().
method1 completed.
Normal flow.
ExceptionPropagationDemo2.java
public class ExceptionPropagationDemo2
{

    public static void main(String[] args)
    {
        ExceptionPropagationDemo2 exceptionPropagationDemo2 = new ExceptionPropagationDemo2();
        exceptionPropagationDemo2.method1();
        System.out.println("Normal flow.");
    }

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

    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.
Exception in thread "main" java.lang.NullPointerException
    at ExceptionPropagationDemo2.method3(ExceptionPropagationDemo2.java:28)
    at ExceptionPropagationDemo2.method2(ExceptionPropagationDemo2.java:21)
    at ExceptionPropagationDemo2.method1(ExceptionPropagationDemo2.java:14)
    at ExceptionPropagationDemo2.main(ExceptionPropagationDemo2.java:7)
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ExceptionDemo_Exception_in_detail_App.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/969ffd88eb34c4fd42d966118b27490392b78865/BasicJava/ExceptionDemo_Exception_in_detail_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