2012-03-20 3 views
1

나는 혼란 스럽다. 함수에서 승인되지 않은 사용자에 대한 예외가 발생했습니다. 나는이 함수를 호출 할 때 그것은 * 치명적인 오류를 보여줍니다 catch되지 않은 예외 'HTTPErrorException'* 내 코드가처리하는 방법 PHP에서 HTTPErrorException

throw new HTTPErrorException ('You are not allowed to access this method.', 401); 

입니다 내가 대신이다 스택 추적의 일부 CSS를 표시 할 수 있도록 내가이 예외를 잡을 수있는 방법

+0

에 대한 자세한

function exception_handler($exception) { echo "Custom Exception: " , $exception->getMessage(), "\n"; } set_exception_handler('exception_handler'); 

검사는 "** 일부 ** CSS를 보여"?! – ThiefMaster

답변

3

오류 코드는 예외를 발견하지 못했음을 나타내므로이 오류가 발생합니다. 모든 예외는 코드에 의해 체포해야

try { 
    .... 
    throw new HTTPErrorException ('You are not allowed to access this method.', 401); 
    .... 
} catch (HTTPErrorException $e) { 
    // generate a stack trace here and show it to user 
    // you can use $e->getTraceAsString() or $e->getTrace() functions here to get stack trace 
} 

또는 당신이 시도 사용하지 않으려면/catch 블록은 당신은 당신의 응용 프로그램이 예외를 catch되지 때마다 호출 될 예외 핸들러 함수를 만들 수 있습니다 어디서든 예외 http://php.net/manual/en/language.exceptions.php

관련 문제