且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

确定System.Net.Mail.SmtpClient.Send结果

更新时间:2023-10-28 09:12:28

catch (ArgumentNullException e) {    return MailSendStatus.ErrorCannotSend;} catch 
(ObjectDisposedException e) {    return MailSendStatus.ErrorCannotSend;} catch 
(InvalidOperationException e) {    return MailSendStatus.ErrorCannotSend;

我不喜欢这个。 ArgumentNull,ObjectDisposed是编程错误(和InvalidOperation一样)。您不应该将它们分解为SMTP错误,而是将其修复。 Fpr这个,崩溃的程序是好的(并放出一个堆栈跟踪)。方法快速失败。不要重新排除异常,你不知道如何处理,而InvalidOperationException,ObjectDisposedException表示状态有问题,ArbumentNullException是一个用法/ ui错误。

I dont like this. ArgumentNull, ObjectDisposed are programming errors (as is InvalidOperation). You should not break them down to a SMTP error but have them fixed. Fpr this, crashing the program is good (and putting out a stack trace). Approach "fail fast". Dont rethriow exceptions you dont know how to handle, and InvalidOperationException, ObjectDisposedException indicate something is wrong with the state, ArbumentNullException is a usage / ui error.