How to handle timeout exception - Smbj

354 views Asked by At

I'm just getting started with java development. My ex-colleagues write a code(Code 1). I recently faced the timeout exception.

Code 1:

    
 public String deleteFiles(String DOMAIN0, String USER, String PASSWORD, String SRC_DIR, String DST_DIR, String ext, String ipAddress, String dstRoot) {
 SmbConfig config = SmbConfig.builder()
                 .withMultiProtocolNegotiate(true)
                 .withSigningRequired(true)
                 .withDfsEnabled(true)
                 .build();
 
 SMBClient client = new SMBClient(config);
 try {
 Connection connection = client.connect(ipAddress);
 AuthenticationContext ac1 = new AuthenticationContext(USER, PASSWORD.toCharArray(), DOMAIN);
 Session session1 = connection1.authenticate(ac1);
 
 DiskShare share1 = (DiskShare) session1.connectShare(SRC_DIR);
 
 if (DST_DIR.contains(".")) {
 if (fileCheckExists) {
 share1.rm(DST_DIR);
 
 else {
 boolean fileCheckExists = share1.folderExists(DST_DIR);
 if (fileCheckExists) {
 share1.rmdir(DST_DIR0, true);
 
 
 
 
 catch (TimeoutException et) {
 return "Error:" + et.getMessage();
 
 catch (Exception ex) {
 return "Error:" + ex.getMessage();
 
 return "Completed";
     }

I added a TimeoutException catch block, but eclipse show the error message(Unreachable catch block for TimeoutException. This exception is never thrown from the try statement body).

catch (TimeoutException et) {
             return "Error:" + et.getMessage();
        }

how to handle the timeout exception. Please suggust me.

0

There are 0 answers