gpt4 book ai didi

PHP 从函数中捕获抛出的 InvalidArgumentException

转载 作者:行者123 更新时间:2023-12-02 20:50:40 26 4
gpt4 key购买 nike

我正在使用 JWS 库来取消签署一些 token ,因此当 token 无效时,我得到了异常 InvalidArgumentException

({ "name": "Exception", "message": "The token \"123\" is an invalid JWS", "code": 0, "type": "InvalidArgumentException", "file": "/var/www/html/checkout/vendor/namshi/jose/src/Namshi/JOSE/J‌​WS.php", "line": 143,)

$jws= SimpleJWS::load($data);

如果 token 无效,静态函数加载会抛出异常,我不想显示异常消息,而是想显示友好的错误消息。

有什么帮助吗?

最佳答案

这个怎么样:

try {
$jws= SimpleJWS::load($data);
// if it's the php exception http://php.net/manual/en/class.invalidargumentexception.php
} catch (\InvalidArgumentException $e) {
// if it's the library's exception you should specify the complete namespace
//} catch (InvalidArgumentException $e) {
// token is not valid
}

关于PHP 从函数中捕获抛出的 InvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42269062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com