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 JsonException

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

功能:JSON 包的异常类,用于 JsonValue 类型使用时出现异常的场景。

父类型:

  • Exception

init()

public init()

功能:构造一个不包含任何异常提示信息的 JsonException 实例。

示例:

import stdx.encoding.json.*

main() {
    // 创建不带消息的JsonException
    try {
        throw JsonException()
    } catch (e: JsonException) {
        println("捕获到 JsonException: ${e.message}")
    }
}

运行结果:

捕获到 JsonException: 

init(String)

public init(message: String)

功能:根据指定的异常提示信息构造 JsonException 实例。

参数:

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

示例:

import stdx.encoding.json.*

main() {
    // 创建带消息的JsonException
    try {
        throw JsonException("JSON解析异常")
    } catch (e: JsonException) {
        println("捕获到 JsonException: ${e.message}")
    }
}

运行结果:

捕获到 JsonException: JSON解析异常