首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[函数]Yar_Server_Exception::getType()函数—用法及示例

发布于 2025-05-19 18:04:52
0
90

(PECL yar >= 1.0.0)

Yar_Server_Exception::getType — 检索异常的原始类型

说明

public Yar_Server_Exception::getType(): string

当服务端的服务函数抛出异常的时候, 客户端本地会响应的抛出一个 Yar_Server_Exception 异常. 有一个属性, 标明了服务端异常的类型. 这个方法就是获取这个异常类型.

参数
此函数没有参数。

返回值
string

示例

示例 #1 Yar_Server_Exception::getType() 示例

//Server.php
<?php
class Custom_Exception extends Exception {};

class API {
    public function throw_exception($name) {
        throw new Custom_Exception($name);
    }
}

$service = new Yar_Server(new API());
$service->handle();
?>

//Client.php
<?php
$client = new Yar_Client("http://host/api.php");

try {
    $client->throw_exception("client");
} catch (Yar_Server_Exception $e) {
    var_dump($e->getType());
    var_dump($e->getMessage());
}
以上示例的输出类似于:

string(16) "Custom_Exception"
string(6) "client"

评论
一个月内的热帖推荐
啊龙
Lv.1普通用户

9545

帖子

31

小组

3242

积分

赞助商广告
站长交流