首頁  >  文章  >  Java  >  java如何在詳細訊息中包含故障捕獲訊息

java如何在詳細訊息中包含故障捕獲訊息

WBOY
WBOY轉載
2023-05-20 23:10:05965瀏覽

在詳細訊息中包含故障擷取訊息

private OutputStream openOutputStream(File file) throws IOException {
    if (file.exists()) {
        if (file.isDirectory()) {
            throw new IOException("File '" + file + "' exists but is a directory");
        }
        if (!file.canWrite()) {
            throw new IOException("File '" + file + "' cannot be written to");
        }
    } else {
        final File parent = file.getParentFile();
        if (parent != null) {
            if (!parent.mkdirs() && !parent.isDirectory()) {
                throw new IOException("Directory '" + parent + "' could not be created");
            }
        }
    }
    return new FileOutputStream(file, false);
}

在這個方法中,IOException 使用不同的字串來傳遞不同的故障擷取訊息。

以上是java如何在詳細訊息中包含故障捕獲訊息的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除