What is actually happening in this code?

Please, tell me what is happening in this code block in as simple english as possible.

try {
    $error = "Always show this error";
    throw new Exception($error);
    
    echo "Never executed";
} catch (Exception $e) {
    echo "Caught exception : ", $e->getMessage(), "\n";
}

echo "Hello World";

you throw an exception. you catch that exception. you proceed.

4 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.