PHP “Exception not found”
来源:互联网 发布:99porn永久域名av123 编辑:程序博客网 时间:2024/06/05 08:40
<?php namespace MyProject;header("Content-Type: text/html; charset=utf-8");error_reporting(0);function theDataBaseObj(){ $mysql = mysql_connect("localhost","roost","root","9096"); if($mysql){ return $mysql; }else{ throw new Exception("Error Connect"); }}function db() { try{ $db = \MyProject\theDataBaseObj(); echo("success"); var_dump($db); }catch(Exception $e){ echo("error"); var_dump($e->getMessage()); }}db();?>
看陈小龙的PHP7实践指南的时候遇到的这个问题,如果成功还无所谓,但是如果你连接数据库失败的话,问题就出现了,你会发错误码255,页面并不会打印出任何东西。
于是很纠结的去翻了翻blog ,文章。
stack overflow上有一个方案解决。
就是添加一下 use Exception
使用原生的Exception ,否则会出现Exception not found;
<?php namespace MyProject;header("Content-Type: text/html; charset=utf-8");use Exception;//看这里,看这里error_reporting(0);function theDataBaseObj(){ $mysql = mysql_connect("localhost","roost","root","9096"); if($mysql){ return $mysql; }else{ throw new Exception("Error Processing Request"); }}function db() { try{ $db = \MyProject\theDataBaseObj(); echo("success"); var_dump($db); }catch(Exception $e){ echo("error"); var_dump($e->getMessage()); }}db();?>
阅读全文
0 0
- PHP “Exception not found”
- TransformerFactoryImpl not found exception
- WordCount not Found Exception
- class not found exception
- Class Not Found Exception
- PHP命名空间中使用Exception报错not found
- Class Not Found Exception解决
- php调用java写的webservices提示Uncaught SoapFault exception: [HTTP] Not Found
- Spring config location file not found exception
- “Class Not Found Exception Spring"解决办法
- .classpath 配置文件 class not found Exception
- overridePendingTransition出现unhandled exception: resource not found
- mybatis class not found exception reasons
- Exception: "dot" not found in path.
- Exception: "dot" not found in path.
- nginx php file not found
- Linux php not found 解决方法
- PHP开发 php-cgi not found
- python 数据采集入门
- PhpStorm中如何使用FTP功能 详细操作方法
- 学习架构图谱
- 由5个不重复的数字组成的任意不重复三位数
- 关于wdcp伪静态。pathinfo的配置。
- PHP “Exception not found”
- invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific
- Python内置模块
- 指定分区表分区进行查询
- 【剑指offer】二进制中1的个数
- RSA加解密过程
- Cortex-M3的特权级别
- 《剑指offer》刷题笔记(递归和循环):变态跳台阶
- think in java 第十五章 泛型 总结随笔