Fix for Issue #3501

I just added a check for $e->getCode() return value, to fix Issue #3501