草庐IT

catch-exception

全部标签

php - 在 Laravel/Lumen 中,为什么 catch block 没有捕获我的异常?

在Laravel/LumenPHP框架中捕获异常的最佳方法是什么?这很可能是一个普遍适用于PHP的问题。目前,我有一个UsersController调用(在tryblock中)我的User类中的“findByUsernameOrFail”方法。如果找不到用户名,此方法将抛出异常,但catchblock未捕获异常!为什么?classUsersControllerextendsController{publicfunctionshow($username){try{$user=\App\User::findByUsernameOrFail($username);return$user;}c

php - 如何使用 .htaccess 将所有页面重定向到 https,但有异常(exception)?

我已经使用htaccess强制所有页面使用...重新路由到httpsRewriteEngineonRewriteBase/RewriteCond%{SERVER_PORT}80RewriteRule^(.*)$https://ourdomain.com/$1[R,L]有什么方法可以为ourdomain.com/videos&&ourdomain.com/blog撤销该规则,确保这些页面被迫放弃https并使用http? 最佳答案 您已经完成了使用RewriteCond将重写限制为端口80上的请求的部分。您不想为/videos和/bl

php - fatal error : Uncaught exception 'Parse\ParseException' with message in parse sdk

我使用以下代码获取数据库数据:require'autoload.php';$app_id='AAAAA';$rest_key='XXXXX';$master_key='RRRRR';useParse\ParseObject;useParse\ParseQuery;useParse\ParseACL;useParse\ParsePush;useParse\ParseUser;useParse\ParseInstallation;useParse\ParseException;useParse\ParseClient;useParse\ParseAnalytics;useParse\Par

php - LARAVEL -> 为什么 try catch 在 Laravel 中不起作用?

我在RouteServiceProvider中有代码:$router->bind('user',function($value){try{throw(new\Symfony\Component\HttpKernel\Exception\NotFoundHttpException);}catch(Exception$e){exit('nott');}});我没有得到输出nott我得到了Sorry,thepageyouarelookingforcouldnotbefound.NotFoundHttpExceptioninRouteServiceProvider.phpline75:...编

php - JWT 解码 try catch

我在我的小项目中使用JWT进行授权(RESTAPI)。JWT看起来非常适合我的项目。假设我有这段代码:$key="secret";$token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"$data=JWT::decode($token,$key,array('HS256'));此代码将返回一个数组,如JWT的官方页面所示。​​但是

php - 无法使用 gmail SMTP 在 Zend 中发送电子邮件。收到 fatal error : Uncaught exception 'Zend_Mail_Protocol_Exception' . 如何解决?

我正在尝试使用GmailSMTP发送电子邮件。以下是我的代码。$mail=newZend_Mail();$config=array('ssl'=>'ssl','port'=>'465','auth'=>'login','username'=>'username@gmail.com','password'=>'mypassword');$transport=newZend_Mail_Transport_Smtp('smtp.gmail.com',$config);$sendNow=$mail->setBodyHtml($message)->setFrom('username@gmail.

php - 使用 symfony 2.8 框架创建项目时出现 GuzzleHttp\Exception\RequestException

首先,我通过以下命令创建了symfony文件:php-r"file_put_contents('symfony',file_get_contents('https://symfony.com/installer'));"之后,我执行了以下命令来创建一个symfony项目:phpsymfonynewmy_project2.8结果:[GuzzleHttp\Exception\RequestException]cURL错误60:SSL证书问题:无法获取本地颁发者证书那么,这个问题有解决办法吗? 最佳答案 从这里下载cacert.pem文件

php - 未捕获异常 'Zend\ModuleManager\Exception\RuntimeException',消息为“模块(相册)无法初始化

我已经安装了运行良好的骨架应用程序,并且我已经创建了新模块。模块名称为“Album”。在创建模块尝试运行代码后,我收到了错误。这里发布我的代码:模块.phparray(__DIR__.'/autoload_classmap.php',),'Zend\Loader\StandardAutoloader'=>array('namespaces'=>array(__NAMESPACE__=>__DIR__.'/src/'.__NAMESPACE__,),),);}publicfunctiongetConfig(){returninclude__DIR__.'/config/module.co

php - 新手 : throw new exception - can we change exception name?

我正在尝试处理异常(exception)情况。所以我有类似的东西:如果发生不好的事情:thrownewCreateContactException($codigo,$result->msg);稍后,我会尝试,如果不行,捕获:try{createContact();}catch(CreateContactException$e){$error.='Anerroroccurredwiththecode:'.$e->getCode().'andmessage:'.$e->getMessage();}1)这行得通吗?我的意思是,这个getCode()和getMessage()与CreateCo

php - 我可以在将 html 文件加载到 DOMDocument 时 try catch PHP 警告吗?

是否有可能进行某种trycatch来捕获警告?例如if(!$dom->loadHTMLFile($url)){//ifcantloadfilehandleerrormyway}对于我正在使用的$urlWarning(2):DOMDocument::loadHTMLFile(MYURL)[domdocument.loadhtmlfile]:failedtoopenstream:HTTPrequestfailed!HTTP/1.0403Forbidden[APP\controllers\import_controller.php,line62]Warning(2):DOMDocument: