symfony/symfony — Issue #2781: FullTransformer DateTime binding exception is not caught in Symfony\Component\Form\Form
Author: Entea
Created: 2011-12-03 12:11:19+00:00
State: open

# Problem

**Symfony\Component\Locale\Stub\DateFormat\FullTransformer** **parse** method throws **\InvalidArgumentException** when the date format does not match.

```
public function parse(\DateTime $dateTime, $value)
{
$reverseMatchingRegExp = $this->getReverseMatchingRegExp($this->pattern);
$reverseMatchingRegExp = '/^'.$reverseMatchingRegExp.'$/';

$options = array();

if (preg_match($reverseMatchingRegExp, $value, $matches)) {
$matches = $this->normalizeArray($matches);

foreach ($this->transformers as $char => $transformer) {
if (isset($matches[$char])) {
$length = strlen($matches[$char]['pattern']);
$options = array_merge($options, $transformer->extractDateOptions($matches[$char]['value'], $length));
}
}

return $this->calculateUnixTimestamp($dateTime, $options);
}

throw new \InvalidArgumentException(sprintf("Failed to match value '%s' with pattern '%s'", $value, $this->pattern));
}

```

This exception is not caught in **Symfony\Component\Form\Form** and form binding fails.

# Description
You can easily reproduce this bug while using **datetime form field** with **widget=single_text** option by entering wrong date. When you try to bind request data to form, fatal error occurs.

# Possible solution
* Standartize exceptions used in data transformers
* Catch those exceptions while binding form data, possibly bind **null** to form field value.