Php exception capture

in tp5, you want to execute logic 1 first, execute logic 2 when logic 1 fails, and return an error

if logic 2 also fails.

when I execute the following code, the system executes the error class defined by tp5 instead of the error format defined by myself

related codes

<?php 

try {
    //1
} catch (\Exception $e) {
    // 2
} catch(\Exception $e){
    //
    return $e->getMessage();
}

return "success";
?>

I want to execute my own defined error to return

Php
Jul.14,2021

//
return $e->getMessage();

you all know that this is the error return, so just put the error here in the format you want

.

Exception is the exception base class. All exceptions will achieve this. Sense exception catch priority strategy, you have caught all runtime exceptions in the first catch, so a little catch will not be executed. Continue try in the second code block if necessary. Or custom exceptions.

Menu