Use boolean variable to track if exception happended - Java Object Oriented Design

Java examples for Object Oriented Design:Exception

Description

Use boolean variable to track if exception happended

Demo Code

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Main {
  public static boolean openFile(String name)
  {//w ww  .  ja  v  a2  s.c o m
       boolean fileOpened = false;
       try
       {
             FileInputStream f = new FileInputStream(name);
             fileOpened = true;
       }
       catch (FileNotFoundException e)
       {
       }
       return fileOpened;
  }
}

Related Tutorials