05-17-2009, 12:20 PM
|
#3 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
Here's the code I am messing with (see below) apologies if it isnt easy to read. What i am trying to achieve is i'm happy with catching the error at the end for example but wonder if i can access the error before the end of the script eg. this script will display a login form if you arent logged in already. If you submit an empty form it throws an error which is displayed at the end of the script. However i want to add some code around the form display part to say well if you have submitted the form but an error has bene thrown back then re-display the form code. I guess what i am asking is do i need the catch(Exception $error) code to access the error so i need to nest try statements? Dunno if i am making myself clear but just trying to understand this i.e. before that last statement "catch(Exception $error)" can i access $error or is the catch statement instatitiating an $error object.
Quote:
try {
require_once('./lib/login.class.php');
$login = new Login;
/* Verify the user has login, otherwise redirect to login page */
if($login->verifyAccess()) {
/* User is logged in, display welcome message */
print "Welcome " . $_SESSION['name'];
require_once('inc.loggedin.php');
} else {
/* Check if the form has been submitted. If not, redirect to login page */
if(!isset($_POST['submit'])) {
/* Include the HTML for the form */
require_once('inc.form.php');
}
else {
$username = $_POST['username'];
$password = $_POST['password'];
/* Verify the login details are correct and redirect to secure.php */
$login->verifyLogin($username, $password);
}
}
}
catch(Exception $error) {
print $error->getMessage();
}
|
|
|
|
|