error = $error; } function getMsg(){ echo $this->error; }}try{ $file = 'tets.txt'; if(is_file($file)) $a = fopen($file,'r'); else throw new MyException('文本不存在');}catch(Exception $e){ echo $e->getMessage()."\n"; echo "\n"; echo $e->getMsg()."\n";}die;try { $error = 'Always throw this error'; echo '执行'; $url = 'http://www.baidu.com'; $a = rand(1,10); echo $a; if($a==4){ echo '正常'; }else if($a>=7){ $error = '连接超时或者连接出错,请检查'; throw new Exception($error); }else{ throw new Exception('xxxx错误'); } // Code following an exception is not executed. echo 'Never executed';} catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n";}