我遇到过这个: –
PHP Error handling: die() Vs trigger_error() Vs throw Exception
并且理解抛出异常更好
如何在此代码中替换die并使用throw异常: –
- try
- {
- if ($db = MysqLi_connect($hostname_db,$password_db))
- {
- //do something
- }
- else
- {
- throw new Exception('Unable to connect');
- }
- }
- catch(Exception $e)
- {
- echo $e->getMessage();
- }