Exception::getPrevious
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
Exception::getPrevious — 이전 throwable을 반환합니다.
설명
final public Exception::getPrevious(): ?Throwable
이전 Throwable(Exception::__construct()의 세 번째 매개변수로 전달됨)을 반환합니다.
매개변수
이 함수에는 매개변수가 없습니다.
반환 값
사용 가능한 경우 이전 Throwable을 반환하고 그렇지 않은 경우 null
을 반환합니다.
Examples
예제 #1 Exception::getPrevious() 예제
반복 및 인쇄, 예외 추적.
<?php
class MyCustomException extends Exception {}
function doStuff() {
try {
throw new InvalidArgumentException("You are doing it wrong!", 112);
} catch(Exception $e) {
throw new MyCustomException("Something happened", 911, $e);
}
}
try {
doStuff();
} catch(Exception $e) {
do {
printf("%s:%d %s (%d) [%s]\n", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode(), get_class($e));
} while($e = $e->getPrevious());
}
?>
위의 예는 다음과 유사한 결과를 출력합니다.
/home/bjori/ex.php:8 Something happened (911) [MyCustomException] /home/bjori/ex.php:6 You are doing it wrong! (112) [InvalidArgumentException]
기타
- Throwable::getPrevious() - 이전 throwable을 반환합니다.