Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

EXC.BROADTHROWS

A method should throw exceptions appropriate to the abstraction level. When a method throws exceptions that are too general, like Exception and Throwable, it is difficult for callers to handle errors correctly and do appropriate error recovery.

Vulnerability and risk

When method throws exceptions that are too general, callers have to investigate what kind of problem happened so that they can handle it appropriately. Also, when a method code is changed and a new kind of exception is introduced, it's harder to force all callers to handle it properly.

Mitigation and prevention

A method should throw exceptions appropriate to the abstraction level. When necessary, low-level exceptions can be wrapped with higher-level exceptions.

Example 1

15    public void processFile(String fileName) throws Exception {
16      InputStream is = new FileInputStream(fileName);
17      // do something
18    }
19    public int calculateSum(Collection data) throws Throwable {
20      int sum = 0;
21      for (Iterator it = data.iterator(); it.hasNext();) {
22        String element = (String) it.next();
23        int i = Integer.parseInt(element);
24        sum += i;
25      }
26      return sum;
27    }

EXC.BROADTHROWS is reported for method 'processFile' declaration on line 15: The 'processFile' method throws a generic exception 'java.lang.Exception'.

EXC.BROADTHROWS is reported for method 'calculateSum' declaration on line 19: The 'calculateSum' method throws a generic exception 'java.lang.Throwable'.