Finding errors in code can be very hard, and doing so without any clues is very very hard. Unfortunately that's the potential problem facing everyone using the new installable event handlers. The scripts that we write to handle events aren't initiated directly by a user at a screen, so there's no immediate place to report error messages and problems. As a result we're frequently baffled as to why our scripts don't work as expected!
Here's a simple trick for catching errors and emailing them to yourself. We're relying on a very nice feature of JavaScript called Exception Handling, and you can learn more about it here. We take the existing event handler:
function myFunc(){
// put your event handling code here.
}
and simply wrap it in a try/catch block:
function myFunc(){
try{
// put your event handling code here.
} catch(error){
MailApp.sendEmail("me@example.com",
"Error Handling Event!",
"Error: " + error);
}
}
Now every time your Event Handling code breaks, you'll get an email telling you all about it.
Sunday, June 6, 2010
Subscribe to:
Post Comments (Atom)
What would be great is if there could be offline logging. Currently, we can set our own entries into the log, but only when directly running and testing.
ReplyDeleteWhat if there were a persistently stored log, that could be written to as the scripts are run via events or even directly by other users, then the developer of the script could reference this log. Rather than getting bombarded by emails using this method.
@Bob
ReplyDeletetry this:
function errorTest() {
try{
var anError = SpreadsheetApp.LOOKanERROR();
//...more of your code...
}catch(error){
var errorSheet = SpreadsheetApp.openById('YourSheetID').getSheetByName('errors');
lastRow = errorSheet.getLastRow();
var cell = errorSheet.getRange('a1').offset(lastRow, 0);
cell.setValue(error);
}
}
I think that could faster this code:
ReplyDeleteSpreadsheetApp.openById("spreadsheetKey").getSheetByName("MySheet").appendRow("Error"+MyError);
asics shoes
ReplyDeletebeats headphones
michael kors bags
michael kors outlet
michael kors outlet clearance
nike trainers
air jordans
kobe 11
canada goose outlet
coach outlet store online
louboutin pas cher
kate spade outlet
cheap jordan shoes
ugg slippers
ralph lauren polo
michael kors uk
cheap jordan shoes
coach factory outlet
oakley sunglasses
coach outlet store online
nike running shoes
louis vuitton outlet
hollister clothing
nfl jerseys wholesale
adidas shoes
jordans
gucci outlet
ray ban sunglasses
louis vuitton
ugg boots
louis vuitton bags
coach factorty outlet
oakley outlet
true religion jeans
louis vuitton handbags
michael kors outlet online
2016324yuanyuan
replica bags online j77 n1f81y5n41 high replica bags v67 n2a34g7q19 high quality designer replica q02 p1u68b0q52
ReplyDelete