otFoundException与NoSuchFileExcep

otFoundException与NoSuchFileExcep

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

问题描述

我注意到另一个Java异常表示该文件不存在 - NoSuchFileException 。我的任务是重构一些api,它们都是从不同的方法中抛出的,我只想使用一个。

I noticed another Java exception for indicating that file does not exist - NoSuchFileException. I was tasked to refactor a certain api which throws both of these from differen methods and I would like to use just one.

我应该将 NoSuchFileException 映射到 FileNotFoundException ?我应该使用 NoSuchFileException 而不是 FileNotFoudnException ,因为它更具体?

Should I map NoSuchFileException to file to FileNotFoundException ? Should I use NoSuchFileException instead of FileNotFoudnException because it is more specific?

编辑:更新了问题。在发布此问题之前,我阅读了文档,并了解了基本的区别。我希望在这种情况下提供更多信息和指导,因为类型的异常处理对于服务api的客户端很重要,我想避免在需要为两种异常类型执行检查的情况下。

Updated the question. I read the documentation before posting this question and know the basic difference. I was hoping for additional information and the guidance in this case since exception handling by type is important for the clients of the service api and I would like to avoid the case when the check needs to be done for both exception types.

推荐答案

文档不言自明。

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

09-02 13:42