PHP에 대해 읽고있는 중에 나는 try {}
과 catch {}
을 본 사람이 무엇을 의미하는지 궁금합니다.PHP에서 예외가 발생했습니다. 설명해주세요.
0
A
답변
2
엔트리 레벨 프라이머를 예외 :
function doSomething($arg1)
{
if (empty($arg1)) {
throw new Exception(sprintf('Invalid $arg1: %s', $arg1));
}
// Reached this point? Sweet lets do more stuff
....
}
try {
doSomething('foo');
// Above function did not throw an exception, I can continue with flow execution
echo 'Hello world';
} catch (Exception $e) {
error_log($e->getMessage());
}
try {
doSomething();
// Above function DID throw an exception (did not pass an argument)
// so flow execution will skip this
echo 'No one will never see me, *sad panda*';
} catch (Exception $e) {
error_log($e->getMessage());
}
// If you make a call to doSomething outside of a try catch, php will throw a fatal
// error, halting your entire application
doSomething();
기능을 배치하여/방법은 try/catch 블록 내에서 호출하면 응용 프로그램의 흐름 실행을 제어 할 수 있습니다.
1
PHP 꽤 좋은 문서를 가지고 - 당신은 거기서부터 시작해야합니다
관련 문제
- 1. PHP에서 httpd.exe에서 처리되지 않은 win32 예외가 발생했습니다.
- 2. 예외가 발생했습니다.
- 3. 예외가 발생했습니다.
- 4. 설명해주세요 AsParallel()
- 5. CloseHandle()에서 예외가 발생했습니다. 외부 구성 요소에서 예외가 발생했습니다.
- 6. Microsoft.Xna.Framework.ni.dll에서 'System.ArgumentException'유형의 예외가 발생했습니다.
- 7. OpenJPA로 OutofMemory 예외가 발생했습니다.
- 8. SimpleDateFormat 예외가 발생했습니다
- 9. deserialize 프로세스에서 예외가 발생했습니다.
- 10. AnthillPro 시작시 예외가 발생했습니다 :
- 11. 'System.Windows.Forms.AxHost + InvalidActiveXStateException'유형의 예외가 발생했습니다.
- 12. "예외가 발생했습니다"나쁜 행동입니까?
- 13. 인터페이스 - null 예외가 발생했습니다
- 14. 평가에서 예외가 발생했습니다.
- 15. iPhone에서 예외가 발생했습니다.
- 16. GWT에서 NoSuchMethod 예외가 발생했습니다.
- 17. 커밋 중에 예외가 발생했습니다.
- 18. start.dfs.sh에서 예외가 발생했습니다.
- 19. StaticPropertyWatcher.as에서 예외가 발생했습니다
- 20. 석영에 내 예외가 발생했습니다
- 21. NotificationManager를 사용하여 예외가 발생했습니다.
- 22. 파일 처리시 예외가 발생했습니다
- 23. 서비스에서 SOAP 예외가 발생했습니다.
- 24. Android에서 Saxparser 예외가 발생했습니다.
- 25. createWindowEx 예외가 발생했습니다.
- 26. 'System.Windows.Setter'를 초기화하면 예외가 발생했습니다.
- 27. 오우거 SDK 예외가 발생했습니다.
- 28. FAIL - 예외가 발생했습니다. org.apache.catalina.LifecycleException
- 29. null 예외가 발생했습니다.
- 30. BluetoothAdapter.getDefaultAdapter() 예외가 발생했습니다
http://stackoverflow.com/questions/933081/try-catch-statements-in-php 유용 할 수 있습니다. –
이것은 매우 기본입니다. 프로그래밍의 기본 사항을 이해할 수 있도록 좋은 PHP 책을 골라 읽는 것이 좋습니다. –