
NumberFormatter::getErrorCode 메소드는 오류코드를 반환합니다. 오류코드를 얻는 방법은 다음과 같습니다.
- 오류코드를 얻는 메소드인 getErrorCode를 사용합니다.
- 예를 들어, InvalidArgumentError를 발생시키는 경우 오류코드를 얻는 방법은 다음과 같습니다.
#hostingforum.kr
php
try {
$formatter = new NumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->format('abc');
} catch (Exception $e) {
echo $e->getCode(); // 1
}
- 위의 예시 코드에서, NumberFormatter::format 메소드에 잘못된 값을 전달하여 InvalidArgumentError가 발생합니다.
- catch 블록에서 $e->getCode()를 사용하여 오류코드를 얻을 수 있습니다.
2025-07-22 02:19