<?php
header("Content-Type: text/html; charset=UTF-8");
function chkNum($num){
if($num > 1){
throw new Exception("숫자가 1보다 큼");
}
return true;
}
try{
chkNum(2);
print "숫자는 1보다 작음";
}catch(Exception $e){
print "메세지: ".$e->getMessage();
}
?>
<?php
header("Content-Type: text/html; charset=UTF-8");
class customException extends Exception{
public function errorMsg(){
$errMsg = "에러 발생 라인: ".$this->getLine().",
에러파일: ".$this->getFile().",
에러메세지: ".$this->getMessage();
return $errMsg;
}
}
$email = "this@hhhh";
try{
if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE){
throw new customException($email);
}
}catch(customException $e){
echo $e->errorMsg();
}
?>
'PHP > 새로운문법' 카테고리의 다른 글
php insert_id 입력된 바로 그값의 PK(Primary Key)를 가져오는 명령 (0) | 2017.11.14 |
---|---|
배열, 연관배열 그리고 forEach (0) | 2017.11.11 |
간단한 로그인예제(Session) (0) | 2017.11.09 |
PDO 데이터 베이스 접속 (0) | 2017.11.09 |
쿠키 (0) | 2017.11.08 |