Your continue is not correct in this context. Which error do you get ?
Mar 23, 2015
11
Level 1
L5: Catch exception in class
I am building a REST API which handles csv file uploads.
Basically, i am trying to check if a string is valid for DateTime constructor and in case its not, respond with an error instead of throwing an exception.
Here is what the code looks,
Inside a foreach loop
try {
$date = new \DateTime('2013-10-30 - 12:08:32'); // invalid format
} catch (Exception $e) {
$errors[] = 'Invalid purchase date format';
continue;
}
Issue is the execution skips this step and jumps to App\Exceptions\Handler.
Is there a way i could prevent it from doing so?
Level 1
@bestmomo - Problem of the missing \. \DateTime instead of DateTime. (facepalm)
try {
$date = new \DateTime('2013-10-30 - 12:08:32'); // invalid format
} catch (\Exception $e) {
dd('I am here');
}
Please or to participate in this conversation.