2012-04-13 3 views
3

도움 수정치명적인 오류 : 날짜 시간 '메시지와 함께 catch되지 않은 예외'예외 '::

Fatal error: Uncaught exception 'Exception' with message 'DateTime::_construct() [datetime.--construct]: Failed to parse time string (--) at position 0 (-): Unexpected character' in Z:\home\plati\www\view.php:110 Stack trace: #0 Z:\home\plati\www\view.php(110): DateTime->_construct('--') #1 {main} thrown in Z:\home\plati\www\view.php on line 110

$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'); 

답변

1

help fix this error

당신은 쉽게 잡기에 의해 예외를 처리 할 수 ​​

, 이것은 당신이 오류에 대해 걱정하지 않아도 의미에서 오류를 수정합니다 더 이상 :

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 예외를 throw합니다.

4

혹시 값 "$newyear-$endmonth-$newday" 인쇄를 시도 해 봤나이 오류? 오류로 인해 변수에 내용이 없어지는 것처럼 보입니다. 그래서 그 문자열의 결과를 게시하십시오. $ A의

1

값은 비어 있습니다; 입력 내용을 확인하십시오.

+0

오 예 $ a는 빈 tyvm입니다 –

관련 문제