Hello all,
I'm new to OOP, I'm having some trouble with exceptions. I've got the hang of throwing and catching them, and even creating my own exception classes, but I'd like to be able to handle the exceptions in a different part of the script then where they occur.
For example, at the top of my script, I validate fields and run my sql inserts and what not. If any of those throw exceptions I want to be able to print an error message in my error message div which is further down in the HTML. I'm not able to keep everything in a try block, because regardless of an exception, I still want to print out a lot of the HTML.
Here's a representation of what I'm trying to do.
<?php
- validate form, if it fails, throw exception
- run sql, if it fails, throw exception
?>
<html>
- some data I want to appear regardless -
- if there are no exceptions, php data will be echoed here
<div id="error_message">
- catch Excpetion
- and display relevant error message
</div>
</html>
I have a feeling I'm thinking about this incorrectly? If this is not what exceptions are meant for, can anyone suggest a better way to do this?
Thanks,
-Jeff