尝试最后阻止继续循环 [英] try-finally block continue for loop

查看:80
本文介绍了尝试最后阻止继续循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个忽略异常的循环,并且效果很好.

I'm writing a loop that ignored the Exception and it works well.

    for (; flag; ) {
        try {
            //do something ignore exception.
            Runnable r = queue.pollFirst();
            r.run();
        } catch (Exception ignored) {
            // ignored.
        }
    }

但是我的问题是:如果我没有捕获RuntimeException 并在 finally 块中强制 continue 循环,那么异常会发生什么并返回值?

But my question is: If I don't catch RuntimeException and force continue loop in finally block, what will happen to the Exception and returned value?

示例:

    for (int i = 0; i < 10; i++) {
        try {
            System.out.println(i);

            throw new RuntimeException();
        } finally {
            //what will happen to the exception if continue loop?
            continue;
        }
    }

推荐答案

它们将是ignored,因为finally块具有final字.

They will be ignored as the finally block has the final word.

这篇关于尝试最后阻止继续循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆