Java异常处理 [英] Java exception handling

查看:92
本文介绍了Java异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要我的程序,我如何使用异常和异常处理来使我的程序继续,即使处理一组文件中某些文件时发生异常?

How do I use exceptions and exception handling to make my program continue even if an exception occurs while processing certain files in a set of files?

为正常文件工作正常,而对于那些在程序中引起异常的文件,它应该忽略。

I want my program to work fine for correct files while for those files which cause an exception in program, it should ignore.

请问,

magggi

推荐答案

for(File f : files){
   try {
       process(f); // may throw various exceptions
   } catch (Exception e) {
       logger.error(e.getMessage(), e);
   }
}

这篇关于Java异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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