异常处理(五)

 1 // address格式:"192.131.2.33:7896"
 2 public void parseRedisAddress(String address) {
 3   this.host = RedisConfig.DEFAULT_HOST;
 4   this.port = RedisConfig.DEFAULT_PORT;
 5   
 6   if (StringUtils.isBlank(address)) {
 7     return;
 8   }
 9 
10   String[] ipAndPort = address.split(":");
11   if (ipAndPort.length != 2) {
12     throw new RuntimeException("...");
13   }
14   
15   this.host = ipAndPort[0];
16   // parseInt()解析失败会抛出NumberFormatException运行时异常
17   this.port = Integer.parseInt(ipAndPort[1]);
18 }

 

posted @ 2022-10-31 07:52  add_oil  阅读(13)  评论(0编辑  收藏  举报