addressbook.class.php
changeset 6 48ffdc97f54b
parent 5 879f0956be86
child 7 47446e75ceea
--- a/addressbook.class.php	Wed Oct 26 00:15:59 2011 +0200
+++ b/addressbook.class.php	Wed Oct 26 00:37:13 2011 +0200
@@ -1,10 +1,13 @@
 <?
+
 interface Address_Book {
     public function get_entries();
     public function search_entries($pattern);
     public function add_entry($entry);
 }
 
+class Address_Book_Exception extends Exception { }
+
 class Address_Book_File implements Address_Book {
 
     const RS = "\n";
@@ -15,7 +18,8 @@
 
     function __construct($file) {
 	@mkdir(dirname($file));
-	$this->fh = fopen($file, "a+b");
+	@$this->fh = fopen($file, "a+b");
+	if (!$this->fh) throw new Address_Book_Exception("Can't open address book.");
 	flock($this->fh, LOCK_EX);
 	$stat = fstat($this->fh);
 	if ($stat['size'] == 0) {