main should throw an exception more specific than Exception
18
19public class Main {
20
21 public static void main(String[] args) throws Exception {22 InputStream content = TransferConfig.class.getClassLoader().getResourceAsStream("app.json");
23 ObjectMapper objectMapper = new ObjectMapper();
24 List<TransferConfig> list = objectMapper.readValue(content, new TypeReference<List<TransferConfig>>() {
sftpDown should throw an exception more specific than Exception
92 */
93
94 public static File sftpDown(String username, String password, String ip, int port, String filepath)
95 throws Exception { 96 Channel channel = null;
97 Session session = null;
98 JSch jsch = new JSch();
sftpUp should throw an exception more specific than Exception
42 */
43
44 public static void sftpUp(String username, String password, String ip, int port, String filepath, File localfile)
45 throws Exception { 46 Session session = null;
47 Channel channel = null;
48 JSch jsch = new JSch();
ftpDown should throw an exception more specific than Exception
185 * @throws SocketException,IOException ,FileNotFoundException
186 */
187 public static File ftpDown(String username, String password, String ip, int port, String filepath)
188 throws Exception {189 FTPClient ftpClient = new FTPClient();
190 FileOutputStream outSteam = null;
191 File localfile = null;
ftpUp should throw an exception more specific than Exception
147 * @throws SocketException,IOException ,FileNotFoundException
148 */
149 public static void ftpUp(String username, String password, String ip, int port, String filepath, File localfile)
150 throws Exception {151 FTPClient ftpClient = new FTPClient();
152 FileInputStream inStream = null;
153 try {
Description
throws
clauses should not contain generic exception types such as Throwable
, Exception
, or RuntimeException
.
Instead, extend RuntimeException
and create more specific exception types which are relevant to your use case.
This issue will be reported for method and constructor declarations with throws
clauses that contain any of the following exception types:
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
Bad Practice
Avoid using overly generic exception types:
public float getPercent() throws RuntimeException { ... }
Recommended
Use a more specific exception type instead.
class CalculationException extends RuntimeException {
// ...
}
// ...
public float getPercent() throws CalculationException { ... }