#23944: Django should use custom exceptions for errors thrown by send_mail
(etc.),
not smtplib.SMTPException
-------------------------------+--------------------------------------
Reporter: jordanreiter | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by berkerpeksag):
I don't think subclassing will be enough in some cases. Some exceptions
will have additional attributes, and the user may need to catch these
exceptions and do something with their attributes. For example:
{{{#!python
try:
send_mail()
except FooException as exc:
if exc.err_code == 42:
logger.exception("...")
raise
}}}
With a generic exception, the user will also need to check whether
`err_code` is defined or not:
{{{#!python
from django.core.mail.exceptions import EmailError
try:
send_mail()
except EmailError as exc:
if getattr(exc, "err_code", 0) == 42:
logger.exception("...")
raise
}}}
or:
{{{#!python
from django.core.mail.exceptions import EmailError
try:
send_mail()
except EmailError as exc:
if issubclass(exc, FooException) and exc.err_code == 42:
logger.exception("...")
raise
}}}
or, catch the `FooException` explicitly:
{{{#!python
from django.core.mail.exceptions import EmailError
try:
send_mail()
except FooException as exc:
if exc.err_code == 42:
logger.exception("...")
raise
except EmailError:
pass
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23944#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.c9158e7444473ceb0144346e8c7d6f60%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.