集册 Java实例教程 重新抛出Java中的异常

重新抛出Java中的异常

欢马劈雪     最近更新时间:2020-01-02 10:19:05

554
重新抛出Java中的异常
/* from 时代Java - N o w  J a v a . c o m*/

import java.io.IOException;

import java.net.URI;

import java.net.URISyntaxException;

import java.nio.file.DirectoryNotEmptyException;

import java.nio.file.Files;

import java.nio.file.NoSuchFileException;

import java.nio.file.Path;

import java.nio.file.Paths;


public class Main {


    public static void main(String[] args) {

        try {

            deleteFile(Paths.get(new URI("file:///tmp.txt")));

        } catch (URISyntaxException ex) {

            ex.printStackTrace();

        } catch (IOException ex) {

            ex.printStackTrace();

        }


    }/**NowJava.com - 时  代  Java**/


    private static void deleteFile(Path path) throws NoSuchFileException, DirectoryNotEmptyException {

        try {

            Files.delete(path);

        } catch (IOException ex) {

            if (path.toFile().isDirectory()) {

             
展开阅读全文