Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Exceptions-1

public class HelloWorld
{
     public static void main(String []args)
     {
        String myMessage = null;

        try
        {
            myMethod(myMessage);
        }
        catch (NullPointerException e)
        {
            System.out.println("Caught a null pointer exception!");
        }
        catch (Exception e)
        {
            System.out.println("Caught an exception: " + e.getClass() + ": " + e.getMessage());        
        }
        finally
        {
            System.out.println("finally block always executed");
        }
    
        System.out.println("Hello World");
     }
     
     public static void myMethod(String s)
     {
         System.out.println(s.length());
     }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.