이 문제는 이미 문제를 해결했기 때문에 설명서 일 뿐이지 만 디버깅하기에는 미묘하고 어렵 기 때문에 공개 영역에서 유용하다고 생각했습니다.예외가 객체 메서드 내부에서 발견되지 않음
문제는 내가 작동하지 않는 개체 메서드에서 try/catch 블록을 가졌다는 것이 었습니다.
TestClass.php :
<?php
//TestClass.php
namespace MyTest;
class TestClass {
public function __construct() {
\e("Initializing object");
try {
\e("Trying object exception");
\throwTestException("Failing gracefully in object");
\e("After exception");
} catch (Exception $e) {
\e($e->getMessage());
}
\e("After object init exception");
}
}
?>
Main.php :로드 Main.php에
<?php
//Main.php
function e($str) { echo "\n$str"; }
function throwTestException($msg) {
throw new RuntimeException($msg);
}
require "TestClass.php";
e("Beginning");
try {
e("First try");
throwTestException("Failing gracefully first");
e("After exception");
} catch (Exception $e) {
e($e->getMessage());
}
e("Ending");
e('');
e('Beginning object test');
new \MyTest\TestClass();
e('Ending object test');
?>
예상 결과이 있었다 감소 된 예는 다음과 같이 두 개의 파일에 있습니다 :
: 내가 실제로 가지고 무엇Beginning
First try
Failing gracefully first
Ending
Beginning object test
Initializing object
Trying object exception
Failing gracefully in object
After object init exception
Ending object test
은 다음과 같이이었다
Beginning
First try
Failing gracefully first
Ending
Beginning object test
Initializing object
Trying object exception
Fatal Error: Uncaught Exception: Failing gracefully in object......
보시다시피 예외는 발견되지 않았습니다. 나는 여러 가지 일을 시도했지만 왜 잡히지 않았는지 알 수 없었다. 그리고 .... (아래 답변 참조)