Java-8 Lambda表达式 - 处理异常

时间:2016-08-22 19:25:58

标签: lambda java-8

我有这个表达式

的lambda表达式
institutionUserConnectionService.getActiveInstitutionUserConnectionsByUser(u)

抛出BusinessWxception。是否有可能处理此异常?

users.parallelStream()
    .forEach(u -> institutionUserConnections
        .addAll(institutionUserConnectionService
             .getActiveInstitutionUserConnectionsByUser(u)));

1 个答案:

答案 0 :(得分:1)

不确定

users.parallelStream()
     .forEach(u -> {
         try {
             institutionUserConnections.addAll(
                 institutionUserConnectionService.getActiveInstitutionUserConnectionsByUser(u)));
         }
         catch (BusinessWxception e) {
             // decide what to do here
         }
    });