ER-046 Method declares too general exception types (Exception, Throwable) in throws clause

Severity2
Enabledyes
Waivable
Configuration
Not allowed exceptions:
exception: java.lang.RuntimeException	exception: java.lang.Exception	exception: java.lang.Throwable	
RationaleApplication shall define exception handling strategy and own exception classes to throw,
Violation
public int getFirstByte(final String fName)throws Exception {
	InputStream is = new FileInputStream(fName);
	return is.read();
}
Fix
public int getFirstByte(final String fName)throws HammurapiTestCasesException {
	try {
		InputStream is = new FileInputStream(fName);
		return is.read();
	} catch (java.io.IOException e) {
		logger.error(FILE_ERROR_TXT, e);
		throw new HammurapiTestCasesException(e);
   	}
}


Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.