require_once 'PEAR.php'; function divide($num1, $num2) { if($num2 == 0) { PEAR::throwError('Cannot divide by zero', 100); } return $num1/$num2; } try { $result = divide(5, 0); } catch(PEAR_Exception $e) { echo "Error: ".$e->getMessage()." (Code: ".$e->getCode().")"; die(); } echo $result;
require_once 'MDB2.php'; $db = MDB2::connect('mysql://user:password@localhost/mydatabase'); if(MDB2::isError($db)) { PEAR::throwError($db->getMessage(), $db->getCode()); }In this example, the MDB2 database connection is established. The isError function is used to check if there was an error while connecting to the database. If there was an error, the PEAR::throwError function is called to throw an exception with the message and code from the MDB2 error object.