Using Exceptions for Form Errors/Messages
Posted: Tue Sep 25, 2007 12:33 am
Hi
Im thinking of using a specific exception class for form errors generated by users - like mandatory input field left empty etc.
But I remembered that Exception stores filename and linenumber and has stack tracing routines etc, exceptions are mainly designed for development errors, not for html-form messages.
Is it a bad idea to use an Exception for this purpose ?
Thanks
Im thinking of using a specific exception class for form errors generated by users - like mandatory input field left empty etc.
Code: Select all
class Ex_User extends Exception
{
public function __construct($message)
{
parent::__construct($msg);
}
}
try
{
//
}
catch (Ex_MySQL $e)
{
//
}
catch (Ex_User $e)
{
$msg = $e->getMessage(); // Display this msg in the html page as an error message to the user
}
catch (Exception $e)
{
//
}Is it a bad idea to use an Exception for this purpose ?
Thanks