Skip to content

Instantly share code, notes, and snippets.

@tuanpt-0634
Created August 7, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuanpt-0634/9df885d41b2dd73a5c6f03597fc40dc7 to your computer and use it in GitHub Desktop.
Save tuanpt-0634/9df885d41b2dd73a5c6f03597fc40dc7 to your computer and use it in GitHub Desktop.
Foreach Try Inline
<?php
$options = [1, 2, 3];
foreach ($options as $option) try {
if ($option == 2) {
throw new \Exception('2 is missing!!');
}
echo $option . PHP_EOL;
} catch (\Exception $ex) {
echo "Exception: ", $ex->getMessage(), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment