<html lang="ko">
<head>
<meta charset="UTF-8">
<title>PHP Exception</title>
</head>
<body>
class CustomException extends Exception // Exception 클래스를 상속 받아 예외 정의
{
public function errorMessage()
{
$msg = $this->getMessage()."<br>".
"예외가 발생한 파일 경로 : ".$this->getFile()."<br>".
"예외가 발생한 라인 번호 : ".$this->getLine();
return $msg;
}
}
try
{
try
{
throw new CustomException("예외 메시지"); // 예외 객체 던짐.
}
catch(CustomException $ex) // 예외 처리
{
throw $ex; // catch 블록에서 다시 예외 객체 던짐.
}
}
catch(Exception $ex) // 예외 처리
{
echo $ex->getMessage();
}
</body>
</html>