note 50911 modified in control-structures.break by felipe

From: Date: Mon, 10 Dec 2007 18:48:31 +0000
Subject: note 50911 modified in control-structures.break by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133297@lists.php.net to get a copy of this message
instead of using the while (1) loop with break like suggested in an earlier note, I would rather recommend throwing an exception, e.g.: <?php try { $query = "SELECT myAttr FROM myTable"; $db = DB::connect($dbUrl); if (DB::isError($db)) { throw new Exception("Connection failed"); } /* ... */ } catch (Exception $e) { echo "Error: ".$e->getMessage()."</br>"; } ?> --was-- instead of using the while (1) loop with break like suggested in an earlier note, I would rather recommend throwing an exception, e.g.: <?php try {   $query = "SELECT myAttr FROM myTable"; $db = DB::connect($dbUrl);   if (DB::isError($db)) { throw new Exception("Connection failed"); } /* ... */ } catch (Exception $e) { echo "Error: ".$e->getMessage()."</br>"; } ?> http://php.net/manual/en/control-structures.break.php

« previous php.notes (#133297) next »