This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 121196 - Wrong order of exceptions in surround with try catch
Summary: Wrong order of exceptions in surround with try catch
Status: RESOLVED DUPLICATE of bug 86483
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-05 15:54 UTC by deepakjacob
Modified: 2007-11-05 17:11 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description deepakjacob 2007-11-05 15:54:53 UTC
Surround with try-catch handles exceptions in wrong order.

Consider the follwing code :


package com.dj;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Deepak
 */
public class Test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BufferedInputStream bis = null;
        try {
            File file = new File("a.txt");
            bis = new BufferedInputStream(new FileInputStream(file));
            while(bis.read()!=-1){
                
            }
        } catch (IOException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                bis.close();
            } catch (IOException ex) {
                Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}



for the line " bis = new BufferedInputStream(new FileInputStream(file));" surround with try/catch ---> generates
FileNotFoundException  catch block. 

for the loop " while(bis.read()!=-1){ } " surround with try/catch ---> generates IOException catch block . 


But IDE places IOException catch block over FileNotFoundException  try/catch bloc which generates a compile time error.
Comment 1 Jan Lahoda 2007-11-05 17:11:49 UTC
Duplicate of issue #86483.

*** This issue has been marked as a duplicate of 86483 ***