var onErrObj = {} function myFunction(){ try{ // function code goes here; // add more elements to onErrObj as desired; }catch(e){ onErrObj['data1'] = 'someData'; onErrObj['data'] = 'some Other Data'; errHandler(e,'myFunction'); } function errHandler(e,strFunc){ var message = e.message+'\n in file: '+e.fileName+' on line: '+e.lineNumber; var sendto = 'yourname@youremail.com'; var subject = 'My App encountered an error occured in '+strFunc; var errProps = JSON.stringify(this.onError); message = subject+'\n'+message+'\n onError: '+errProps; GmailApp.sendEmail(sendto, subject, message); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter