Thursday, 30 June 2016

Java Tutorial : Java Exception handling (Specifying the exceptions thrown by a method)


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

Click the below Image to Enlarge
Java Tutorial : Java Exception handling (Specifying the exceptions thrown by a method) 
ThorwsDemo.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ThorwsDemo
{

    public static void main(String[] args)
    {
        ThorwsDemo throwsDemo = new ThorwsDemo();

        try
        {
            String firstLine = throwsDemo
                    .readFirstLineFromFile("myfile.txt");
            System.out.println("firstLine = " + firstLine);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

    }

    public String readFirstLineFromFile(String path)
            throws IOException

    {
        BufferedReader br = new BufferedReader(new FileReader(path));
        String line = br.readLine();
        br.close();
        return line;
    }

}
Output
java.io.FileNotFoundException: myfile.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:93)
    at java.io.FileReader.<init>(FileReader.java:58)
    at ThorwsDemo.readFirstLineFromFile(ThorwsDemo.java:29)
    at ThorwsDemo.main(ThorwsDemo.java:15)
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ExceptionDemo_Specify_Exceptions_Thrown_App.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/4babce59a384cb4ab41f12b03cd7d11227a4b186/BasicJava/ExceptionDemo_Specify_Exceptions_Thrown_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

    Google+ Followers

    Google+ Badge