tell me how to catch the error

new DateTime('12') 

Uncaught exception 'Exception' with message 'DateTime :: __ construct (): Failed to parse string php (1): DateTime -> __ construct ('12 ') # 1 {main} thrown on line 1

If the number is not correct, then set the default as new DAteTime(10-10-2010)

    1 answer 1

     new DateTime('12') 

    What's this? date? time? Better through DateTime :: createFromFormat do

     $date = DateTime::createFromFormat('M', '12'); // 12й месяц 

    Ps If in the case: the parser in the constructor does not understand what it is dealing with.

    UPD:
    I'm sorry. I misunderstood the question.
    If you need to catch an error in the formation of the date, then use exceptions.