How to continue program execution even after throwing exception?

前端 未结 5 1348
盖世英雄少女心
盖世英雄少女心 2021-02-05 23:56

I have a requirement where in program execution flow should continue even after throwing an exception.

for(DataSource source : dataSources) {
    try {
        /         


        
5条回答
  •  盖世英雄少女心
    2021-02-06 00:09

    The logic you have there now does exactly that. If the exception puts DataSource into an invalid state, the next attempt to use the iterator may throw a different exception, but that's a different matter and something specific to DataSource (so you'd have to look at whether DataSource lets you do something to deal with that other invalid state in some way). But in the general case, you're doing it right.

提交回复
热议问题