라이브러리

[PHP] restore_exception_handler - 이전에 정의된 예외 처리기 함수를 복원합니다.




PHP 에서 Restore Exception Handler


PHP 에서 `restore_exception_handler` 함수는 현재 활성화된 예외 처리 핸들러를 원래 상태로 복원합니다. 이 함수는 PHP 7.3 버전부터 사용할 수 있습니다.

예외 처리 핸들러


PHP 에서 예외 처리 핸들러는 `set_exception_handler` 함수를 사용하여 설정할 수 있습니다. 예외가 발생하면 PHP는 현재 활성화된 예외 처리 핸들러를 호출합니다.

예제


#hostingforum.kr
php

// 현재 활성화된 예외 처리 핸들러를 설정합니다.

function exception_handler($exception) {

    echo "예외 발생: " . $exception->getMessage() . "
";

}



set_exception_handler('exception_handler');



// 예외를 발생시킵니다.

try {

    throw new Exception("테스트 예외");

} catch (Exception $e) {

    // 예외 처리 핸들러를 복원합니다.

    restore_exception_handler();

    throw $e;

}



// 예외 처리 핸들러를 복원하지 않으면 예외 처리 핸들러가 호출되지 않습니다.

try {

    throw new Exception("테스트 예외");

} catch (Exception $e) {

    // 예외 처리 핸들러를 복원하지 않습니다.

    echo "예외 발생: " . $e->getMessage() . "
";

}



결과


#hostingforum.kr


예외 발생: 테스트 예외



설명


위 예제에서 `restore_exception_handler` 함수를 사용하여 예외 처리 핸들러를 복원합니다. 이로 인해 예외가 발생했을 때 원래 예외 처리 핸들러가 호출됩니다.

참고


* PHP 공식 문서: [restore_exception_handler](https://www.php.net/manual/kr/function.restore-exception-handler.php)
* PHP 공식 문서: [set_exception_handler](https://www.php.net/manual/kr/function.set-exception-handler.php)
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 273 페이지

검색

게시물 검색