我正在尝试使用以下代码格式化用户输入:
$userInput="blalalbla";//assume the user is inputing wrong data, they are supposed to input it like "12:30"
try{
$timeStr=explode(":",$userInput);
$time=(new Datetime())->setTime($timeStr[0],$timeStr[1]);
}catch(ErrorException $e){
}
但是,如果输入的格式不正确,laravel4 将始终触发 ErrorException,我无法捕捉到它。由于用户输入可能以不同的方式出错,我认为这是处理验证的最优雅的方式。尽管听起来很荒谬,但 ErrorExceptions 似乎无法捕获。我还有什么其他选择?