Send Mail When an Error Occurs

I have a fish function created that allows me to send a mail when the numerical model is completely resolved. How can I make this fish function execute and send me a mail when an error occurs in the resolution of the model?

You can call it using python and try-except statement