Elfy Elfy - 2 months ago 24
PHP Question

Break from try/catch block

Is this possible in PHP?

try{

$obj = new Clas();

if($obj->foo){
// how to exit from this try block?
}

// do other stuff here

}catch(Exception $e){

]


I know I can put the other stuff between
{}
, but that increases indenting on a bigger code block and I don't like it :P

Answer

I know this increases indentation but is an answer

try
{
    $obj = new Clas();
    if ($obj->foo)
    {
        // do stuff here
    }
    else
    {
        // do other stuff here
    }
}
catch (Exception $e)
{
     // handle exceptions here
}