phpexceptiontry-catch

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


Solution

  • try
    {
        $object = new Something();
        if ($object->value)
        {
            // do stuff
        }
        else
        {
            // do other stuff
        }
    }
    catch (Exception $e)
    {
         // handle exceptions
    }