Yar_Server_Exception::getType

(PECL yar >= 1.0.0)

Yar_Server_Exception::getType獲取異常的原始類型

說明

public Yar_Server_Exception::getType(): string

當服務端的服務函數(shù)拋出異常的時候, 客戶端本地會響應的拋出一個Yar_Server_Exception異常. 有一個屬性, 標明了服務端異常的類型. 這個方法就是獲取這個異常類型.

參數(shù)

此函數(shù)沒有參數(shù)。

返回值

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"

參見