[Xunsearch PHP-SDK](http://www.xunsearch.com) v1.4.8 API 參考文檔
# XSException
[All Packages](#)| [屬性](#)| [方法(函數)](#)
| 包 | [XS](#) |
|-----|-----|
| 繼承關系 | class XSException ?Exception |
| 子類 | [XSErrorException](#) |
| 版本 | 1.0.0 |
| 源代碼 | [sdk/php/lib/XS.class.php](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XS.class.php) |
XS 異常類定義, XS 所有操作過程發生異常均拋出該實例
### Protected 屬性
[隱去繼承來的屬性](#)
| 名稱 | 類型 | 描述 | 定義于 |
|-----|-----|-----|-----|
| code | | | Exception |
| file | | | Exception |
| line | | | Exception |
| message | | | Exception |
### Public 方法
[隱去繼承來的方法](#)
| 名稱 | 描述 | 定義于 |
|-----|-----|-----|
| __construct() | | Exception |
| [__toString()](#) | 將類對象轉換成字符串 | XSException |
| getCode() | | Exception |
| getFile() | | Exception |
| getLine() | | Exception |
| getMessage() | | Exception |
| getPrevious() | | Exception |
| [getRelPath()](#) | 取得相對當前的文件路徑 | XSException |
| getTrace() | | Exception |
| getTraceAsString() | | Exception |
### 方法明細
__toString()方法
<table class="summaryTable"><tr><td colspan="3"><div class="signature2">public string <b>__toString</b>()</div></td></tr><tr><td class="paramNameCol">{return}</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">異常的簡要描述信息</td></tr></table>
**源碼:**[sdk/php/lib/XS.class.php#L67](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XS.class.php#L67) (**[顯示](#)**)
`public?function?__toString()
{
????$string?=?'['?.?__CLASS__?.?']?'?.?$this->getRelPath($this->getFile())?.?'('?.?$this->getLine()?.?'):?';
????$string?.=?$this->getMessage()?.?($this->getCode()?>?0???'(S#'?.?$this->getCode()?.?')'?:?'');
????return?$string;
}`
將類對象轉換成字符串
getRelPath()方法
<table class="summaryTable"><tr><td colspan="3"><div class="signature2">public static string <b>getRelPath</b>(string $file)</div></td></tr><tr><td class="paramNameCol">$file</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">需要轉換的絕對路徑</td></tr><tr><td class="paramNameCol">{return}</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">轉換后的相對路徑</td></tr></table>
**源碼:**[sdk/php/lib/XS.class.php#L79](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XS.class.php#L79) (**[顯示](#)**)
`public?static?function?getRelPath($file)
{
????$from?=?getcwd();
????$file?=?realpath($file);
????if?(is_dir($file))?{
????????$pos?=?false;
????????$to?=?$file;
????}?else?{
????????$pos?=?strrpos($file,?'/');
????????$to?=?substr($file,?0,?$pos);
????}
????for?($rel?=?'';;?$rel?.=?'../')?{
????????if?($from?===?$to)?{
????????????break;
????????}
????????if?($from?===?dirname($from))?{
????????????$rel?.=?substr($to,?1);
????????????break;
????????}
????????if?(!strncmp($from?.?'/',?$to,?strlen($from)?+?1))?{
????????????$rel?.=?substr($to,?strlen($from)?+?1);
????????????break;
????????}
????????$from?=?dirname($from);
????}
????if?(substr($rel,?-1,?1)?===?'/')?{
????????$rel?=?substr($rel,?0,?-1);
????}
????if?($pos?!==?false)?{
????????$rel?.=?substr($file,?$pos);
????}
????return?$rel;
}`
取得相對當前的文件路徑
Copyright ? 2008-2011 by [杭州云圣網絡科技有限公司](http://www.xunsearch.com)
All Rights Reserved.
- 權威指南
- 新手上路
- 最新主要變動
- 概述
- 關于 Xunsearch PHP-SDK
- 安裝、升級
- 體驗 demo 項目
- 開發規范
- 開發流程
- 了解基礎對象
- 基礎對象概述
- XS 項目
- XSException 異常
- XSDocument 文檔
- XSIndex 索引管理
- XSSearch 搜索
- XSTokenizer 分詞接口
- 編寫項目配置文件
- 項目配置詳解
- 自定義分詞器
- 編寫第一個配置文件
- 管理索引
- 索引概述
- 添加文檔
- 更新、修改文檔
- 刪除文檔
- 清空索引
- 平滑重建索引
- 使用索引緩沖區
- 自定義SCWS詞庫
- 使用搜索
- 搜索概述
- 構建搜索語句
- 獲取搜索匹配結果
- 獲取搜索匹配數量
- 獲取熱門搜索詞
- 獲取相關搜索詞
- 搜索建議和糾錯
- 按字段值分面搜索
- 使用輔助工具
- RequiredCheck 運行檢測
- Indexer 索引管理器
- Quest 搜索測試工具
- SearchSkel 生成搜索代碼
- IniWizzard 配置文件向導
- Logger 搜索日志管理
- 專題
- 同義詞搜索功能
- 在SDK中使用SCWS分詞
- API 指南
- XS
- XS
- XSCommand
- XSComponent
- XSDocument
- XSErrorException
- XSException
- XSFieldMeta
- XSFieldScheme
- XSIndex
- XSSearch
- XSServer
- XS.tokenizer
- XSTokenizer
- XSTokenizerFull
- XSTokenizerNone
- XSTokenizerScws
- XSTokenizerSplit
- XSTokenizerXlen
- XSTokenizerXstep
- XS.util
- XSCsvDataSource
- XSDataFilter
- XSDatabaseDataSource
- XSDebugFilter
- XSJsonDataSource
- XSUtil
- XS.util.db
- XSDatabase
- XSDatabaseMySQL
- XSDatabaseMySQLI
- XSDatabasePDO
- XSDatabasePDO_MySQL
- XSDatabasePDO_PgSQL
- XSDatabasePDO_SQLite
- XSDatabasePgSQL
- XSDatabaseSQLite
- XSDatabaseSQLite3
- XS.utilf
- XSDataSource
- 其它文檔
- 關于 xunsearch
- 特色和優勢
- Xunsearch 架構簡圖
- 下載 Xunsearch
- 商業服務與支持
- XunSearch 授權許可證