简体   繁体   中英

PHP - try and catch block (Exception) handling

I'm in doubt about exception handling.

If I have a function foo(); is it same as if I handle it like this:

try {
    foo();
} catch (Exception $e) {
    // do someting
}

or if I do it in function like this:

foo() {
    try {
       // function body
    } catch (Exception $e) {
       // do someting
    }
}

And what if I do not throw Exception ? Code will continue to execute even if error appears ?

Yes, code will continue. In php exists errors and exceptions. You can handle errors with function set_error_handler() , handle uncathable exceptions with function set_exception_handler() and you can handle exceptions using try .. catch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM