There are a few functions in php that throw errors when they fail, such as ftp_login
. If I have this code.
try {
$result = ftp_login($conn_id, $ftp_user_name, 'incorrectPassword');
if (!$result) {
throw new Exception('Could not login.');
}
} catch (Exception $e) {
echo $e->getMessage() . ' - ' . error_get_last();
}
It will not catch because of the error. Is the appropriate thing in this case to use an Error Control Operator like so?
try {
$result = @ftp_login($conn_id, $ftp_user_name, 'incorrectPassword');
if (!$result) {
throw new Exception('Could not login.');
}
} catch (Exception $e) {
echo $e->getMessage() . ' - ' . error_get_last();
}
This allows me to react to the error, however it suppresses errors and would be a major performance hit. How can I judge which is the right approach, and is there any other alternatives I'm not considering?