I have to form datelist field. If user select incorrect date, for example 1970-02-31, displayed exception Exception:

The array contains invalid values. in Drupal\Component\Datetime\DateTimePlus::createFromArray() (line 149 of core/lib/Drupal/Component/Datetime/DateTimePlus.php).


  1. Drupal\Component\Datetime\DateTimePlus::createFromArray() called at [/var/www/drupal8/core/modules/datetime/datetime.module:802]
  2. form_type_datelist_value() 2 call_user_func_array() called at [/var/www/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php:1542]
  3. Drupal\Core\Form\FormBuilder->handleInputElement() called at [/var/www/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php:1328]
  4. Drupal\Core\Form\FormBuilder->doBuildForm() called at [/var/www/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php:1390]
  5. Drupal\Core\Form\FormBuilder->doBuildForm() called at [/var/www/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php:1390]

I want override exception to return FALSE, and display to user warning about incorrect date.

How do I it?

  • Can't you just put a try catch statement around the calling code ? May 3, 2014 at 10:47

1 Answer 1


As @Daniel Wehner suggests, this can easily be done by wrapping the calling code in a try - catch block. That's what it is for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.