Algorithm does not enter Catch (Try/catch)

Asked

Viewed 70 times

0

I’m learning programming and came across the Try catch, however my code never enters the catch..

<?php
class NewsLetter{
    public function cadastrarEmail($email){
        if(!filter_var($email,FILTER_VALIDATE_EMAIL)):
            throw new Exception("Este email é invalido",1);
        else:
            echo"ok";
        endif;
    }
}


$Newsletter = new NewsLetter();

try{
    $Newsletter->cadastrarEmail("@haha");
} catch(Expection $e){
    echo"aaaaaaaaaaa";
    echo"Erro: ".$e->getCode();
}
?>

1 answer

1


The problem is you misspelled Exception

catch(Expection $e)

the correct would be

catch(Exception $e)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.