본문 바로가기
MySql

MySQL 치명적인 오류 : 'DateTime ::'메시지와 함께 포착되지 않은 예외 'Exception'

by 베이스 공부 2021. 2. 15.
반응형

이 오류를 수정하는 데 도움

치명적 오류 : 'DateTime :: _ construct () [datetime .-- construct] 메시지와 함께 포착되지 않은 예외'Exception ': 위치 0 (-)에서 시간 문자열 (-)을 구문 분석하지 못했습니다. Z에서 예상치 못한 문자' : \ home \ plati \ www \ view.php : 110 스택 추적 : # 0 Z : \ home \ plati \ www \ view.php (110) : DateTime-> _construct ( '-') # 1 110 행의 Z : \ home \ plati \ www \ view.php에 {main}이 던져졌습니다.

$newday = $a['dayz'];
$endmonth = $a['monthz'];
$newyear = $a['yearz'];
$date = new DateTime("$newyear-$endmonth-$newday");
$date->modify('+8 day');
$year = $date->format('Y');
$month = $date->format('m');
$day = $date->format('d');

 

해결 방법

 

이 오류를 수정하는 데 도움

예외를 잡아서 쉽게 처리 할 수 ​​있습니다. 그러면 더 이상 해당 오류에 대해 신경 쓸 필요가 없다는 의미에서 오류가 수정됩니다.

try {
    $newday = $a['dayz'];
    $endmonth = $a['monthz'];
    $newyear = $a['yearz'];
    $date = new DateTime("$newyear-$endmonth-$newday");
    $date->modify('+8 day');
    $year = $date->format('Y');
    $month = $date->format('m');
    $day = $date->format('d');
} catch(Exception $e) {
    # do nothing
}

적어도 어느 시점에서는 오류 처리를해야합니다. 예외는이를 수행해야하며 DateTime 은 예외를 발생시킵니다.

 

참조 페이지 https://stackoverflow.com/questions/10140915

 

 

반응형

댓글