Get Error Message, Send email with error Message

I’m trying to find a way that if and error happens on the client for any reason like a fail INSERT, or an error writing to a tag, to get that error Message, copy the full details and send by email. or store somewhere. It would be very helpful for startups and debugging.