AnsweredAssumed Answered

try/catch in javascript

Question asked by marutiprasad on Jan 19, 2012
Latest reply on Aug 17, 2015 by mrogers
Hi,

I am using an action to execute a java script which extracts/import a zip to a location xyz. If the zip is corrupted i need to log the same in a log file.In the positive case it is working properly. But in the negative scenatio (if the zip is corrupted) the logging code is not working.

here is my code
var tempnodepath = "repository/temps";
var lognodepath = "repository/LOGS";
var lognode = companyhome.childByNamePath(lognodepath);
var tempnode = companyhome.childByNamePath(tempnodepath);
var errorlog = lognode.childByNamePath("error_log.txt");
if(errorlog == null || errorlog.length = 0){
   errorlog = lognode.createFile("error_log.txt");
}
// take the filename only, remove the extension
var tempfilename = document.properties.name.substring(0,document.properties.name.lastIndexOf("."));
// create the folder
var tempfolder = tempnode.createFolder(tempfilename);
// import the zip into the newly created "temp"
var extractor = actions.create("import");
extractor.parameters.destination = tempfolder.nodeRef;
extractor.parameters.encoding = "utf-8";
try{   
   extractor.execute(document);
   }catch(exception){
   errorlog.content = exception.message + "\r\n";
}

ps: I have configured a rule to execute the above script when a zip is added to the folder called uploads.

Outcomes