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 201720

Summary: Simplifying exception catch block
Product: java Reporter: arungupta <arungupta>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 7.0.1   
Hardware: PC   
OS: Other   
Issue Type: ENHANCEMENT Exception Reporter:

Description arungupta 2011-09-07 05:24:40 UTC
Consider a method as:

private PreparedStatement getStatement() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
...
}

When this method is invoked in another method as:

private void updateDB() {
   ...
   getStatement()
   ...
}

NetBeans IDE shows yellow bulb on "getStatement()" invocation and all the four exceptions need to be explicitly added to throws clause or surround statement/block with try/catch.

An additional hint "Add all exceptions in throws clause" will be useful.

On the same notes, when the statement/block is surrounded with try/catch then the following statement is included in the catch block:

Logger.getLogger(SQLPreparedStatement.class.getName()).log(Level.SEVERE, null, ex);

This is a perfect candidate for using multi-catch. It could be an additional hint or the default as well.
Comment 1 rudolfschmidt 2012-11-21 23:01:19 UTC
I support this bug track. I had the same situation today.

The following code throws two kinds of exception, MalformedURLException and
IOException

URL url = new URL(input);
URLConnection uRLConnection = url.openConnection();
uRLConnection.connect();

netbeans shows two hints:

surround statement with try-catch
surround block with try-catch

but no "surround with multi try-catch" 

it would be nice to get something like:

try {
	URL url = new URL(input);
	URLConnection uRLConnection = url.openConnection();
	uRLConnection.connect();
} catch (MalformedURLException ex) {
	Logger.getLogger(Service.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
	Logger.getLogger(Service.class.getName()).log(Level.SEVERE, null, ex);
}

after a single quick fix.