💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[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.