Friday, 6 September 2013

How to handle this ErrorException in PHP

How to handle this ErrorException in PHP

I'm trying to format user input with the following code:
try{
$timeStr=explode(":",$_POST["time"]);
$time=(new Datetime())->setTime($timeStr[0],$timeStr[1]);
}catch(Exception $e){
}
However, if the input is not in the right format, laravel4 will always
fire an ErrorException and I have no way of catching it. Since the user
input can be wrong in different ways, I thought this was the most elegant
way of handling validation. As ridiculous as it sounds like,
ErrorExceptions seem to be un-catchable. What other options do I have?

No comments:

Post a Comment