I would like to know how to print the string written when raising an exception.
For example if I use
raise ValidationError("RANDOM TEXT HERE");
How can I retreive “RANDOM TEXT HERE” from within the except section.
try:
...
except ValidationError:
...
// something like Java's ex.getMessage();
.....
Thank you
If you bind the exception to a variable, then you could get its string representation with
str(exception_variable).Namely:
Edit: Changed
msgtomessageSecond edit: Realized that exceptions are inconsistent between storing messages in
msgvsmessage.str(exception)seems to be the most consistent.