Exemplo n.º 1
0
                throw new AuthException("No such user");
            }
        }
    }
}
// subclass exceptions
class FileException extends Exception
{
}
class AuthException extends Exception
{
}
// try the code
try {
    // create instance
    $ua = new userAuth("joe", "secret");
    // set password file
    $ua->setPasswdFile("password.txt");
    // perform authentication
    $ua->authenticateUser();
} catch (FileException $e) {
    // print file errors
    print "A file error occurred. " . $e->getMessage();
} catch (AuthException $e) {
    // an authentication error occurred
    print "An authentication error occurred. " . $e->getMessage();
    // more normally, redirect to new page on auth errors, e.g.
    // header ('Location: login_fail.php');
} catch (Exception $e) {
    print "An unknown error occurred";
}