Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

异常类

class ContentFormatException

public class ContentFormatException <: Exception {
    public init()
    public init(message: String)
}

功能:提供字符格式相关的异常处理。

父类型:

init()

public init()

功能:创建 ContentFormatException 实例。

示例:

import std.io.*

main(): Unit {
    try {
        throw ContentFormatException()
    } catch (e: ContentFormatException) {
        println("捕获异常: ${e.message}")
    }
}

运行结果:

捕获异常:

init(String)

public init(message: String)

功能:根据异常信息创建 ContentFormatException 实例。

参数:

  • message: String - 异常提示信息。

示例:

import std.io.*

main(): Unit {
    try {
        throw ContentFormatException("数据格式不正确")
    } catch (e: ContentFormatException) {
        println("捕获异常: ${e.message}")
    }
}

运行结果:

捕获异常: 数据格式不正确

class IOException

public open class IOException <: Exception {
    public init()
    public init(message: String)
}

功能:提供 IO 流相关的异常处理。

父类型:

init()

public init()

功能:创建 IOException 实例。

示例:

import std.io.*

main(): Unit {
    try {
        throw IOException()
    } catch (e: IOException) {
        println("捕获异常: ${e.message}")
    }
}

运行结果:

捕获异常:

init(String)

public init(message: String)

功能:根据异常信息创建 IOException 实例。

参数:

  • message: String - 异常提示信息。

示例:

import std.io.*

main(): Unit {
    try {
        throw IOException("文件读取失败")
    } catch (e: IOException) {
        println("捕获异常: ${e.message}")
    }
}

运行结果:

捕获异常: 文件读取失败