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 ConnectionException

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

功能:Http 的 tcp 连接异常类。

父类型:

  • IOException

init(String)

public init(message: String)

功能:创建 ConnectionException 实例。

参数:

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

示例:

import stdx.net.http.*

main() {
    try {
        throw ConnectionException("connect failed")
    } catch (e: ConnectionException) {
        println("message: ${e.message}")
    }
}

运行结果:

message: connect failed

class CoroutinePoolRejectException

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

功能:Http 的协程池拒绝请求处理异常类。

父类型:

  • Exception

init(String)

public init(message: String)

功能:创建 CoroutinePoolRejectException 实例。

参数:

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

示例:

import stdx.net.http.*

main() {
    try {
        throw CoroutinePoolRejectException("pool rejected")
    } catch (e: CoroutinePoolRejectException) {
        println("message: ${e.message}")
    }
}

运行结果:

message: pool rejected

class HttpException

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

功能:Http 的通用异常类。

父类型:

  • Exception

init(String)

public init(message: String)

功能:创建 HttpException 实例。

参数:

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

示例:

import stdx.net.http.*

main() {
    try {
        throw HttpException("bad request")
    } catch (e: HttpException) {
        println("message: ${e.message}")
    }
}

运行结果:

message: bad request

class HttpStatusException

public class HttpStatusException <: Exception {
    public init(statusCode: UInt16, message: String)
}

功能:Http 的响应状态异常类。

父类型:

  • Exception

init(UInt16, String)

public init(statusCode: UInt16, message: String)

功能:创建 HttpStatusException 实例。

参数:

  • statusCode: UInt16 - 状态码。
  • message: String - 异常提示信息。

示例:

import stdx.net.http.*

main() {
    try {
        throw HttpStatusException(404, "not found")
    } catch (e: HttpStatusException) {
        // statusCode 在实现中为非 public 字段,此处只演示 message
        println("message: ${e.message}")
    }
}

运行结果:

message: not found

class HttpTimeoutException

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

功能:Http 的超时异常类。

父类型:

  • Exception

init(String)

public init(message: String)

功能:创建 HttpTimeoutException 实例。

参数:

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

示例:

import stdx.net.http.*

main() {
    try {
        throw HttpTimeoutException("read timeout")
    } catch (e: HttpTimeoutException) {
        println("message: ${e.message}")
    }
}

运行结果:

message: read timeout

class WebSocketException

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

功能:WebSocket 的通用异常类。

父类型:

  • Exception

init(String)

public init(message: String)

功能:创建 WebSocketException 实例。

参数:

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

示例:

import stdx.net.http.*

main() {
    try {
        throw WebSocketException("ws error")
    } catch (e: WebSocketException) {
        println("message: ${e.message}")
    }
}

运行结果:

message: ws error