You can start with a JavaScript try/catch.
function doPost(e) {
try{
//The code
}catch(e){
//To get the error message use e.message
//To get the stack use e.stack - includes the line that the error occurred on
myErrorHandlingFunction(e);
}
function myErrorHandlingFunction(e) {
//Process the error
}
}
There are sometimes when I like to use Stackdriver to log errors in order to avoid giving permission to sending an email or access to Google Sheets, or when the code is running from a simple trigger which prohibits an external request.
If the code were running from someone else's account, and you didn't want to ask them for permission to send an email or give access to your spreadsheet, then you could make a UrlFetchApp.fetch(my web app url for error processing) call to your account, and then the web app running from your account can access your account.