...
Code Block |
---|
|
boolean isCapitalized(String s) {
if (s == null) {
throw new NullPointerException();
}
if (s.equals("")) {
return true;
}
String first = s.substring( 0, 1);
String rest = s.substring( 1);
return (first.equals( first.toUpperCase()) &&
rest.equals( rest.toLowerCase()));
}
|
Noncompliant Code Example
This noncompliant code snippet uses a broad Exception
class in the throws
statement within the method declaration.
Code Block |
---|
|
private void doSomething() throws Exception {
//...
}
|
Compliant Solution
To be compliant, be as specific as possible while declaring exceptions and heed the given abstraction level.
Code Block |
---|
|
private void doSomething() throws IOException {
//...
}
|
Risk Assessment
Throwing RuntimeException
, Exception
, or General
prevents classes from catching your exception without catching other unintended exceptions as well.
...