动力节点旗下在线教育品牌  |  咨询热线:400-8080-105 学Java全栈,上蛙课网

捕获异常后,如何重新运行try block

德玛西亚丶吼吼

2020.09.04

想请教大家一下捕获异常后,如何重新运行try block

 

添加回答

回答(1)

丑爷

 //循环判断是否超时, 限定重连次数为3次

        int timeoutCount = 0;

        int maxCount = 3 ;

        do{

            try{

            String res = proxy.exchange(xml,tFlag);

            logger.info("[CRM][service]返回报文="+res);

            cRMResDTO = (CRMResDTO)JsonUtil.readValue(res,CRMResDTO.class);

            timeoutCount = maxCount ;

            }catch (ConnectException | ConnectTimeoutException | SocketTimeoutException e){

                logger.error(e.getMessage());

                timeoutCount++;

                logger.info("[CRM][service][连接超时]第"+timeoutCount+"次连接");

            }

        }while(timeoutCount < maxCount);

时间:09-04 14:15 查看回复 (0) 回复 0 0 举报

回复