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 - Simplifying exception catch block
Summary: Simplifying exception catch block
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.0.1
Hardware: PC Other
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-07 05:24 UTC by arungupta
Modified: 2013-11-16 13:06 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.