1 Reply Latest reply on Aug 22, 2013 12:53 AM by bastieneichenberger

    use bridgeTalk with onError event, exception handling

    bastieneichenberger Level 1

      Hi all,

       

      I'm writting a function who use bridgeTalk to execute a photoshop script. This function works but I would like to throw an exception if the script has a problem. I commented a line in my script to have an exception but the onError event doesn't throw my Error.

       

      Have someone an idea?

       

      Thanks!

       

       

       

      function save_to_PSD(obj){
          var bt = new BridgeTalk();
           bt.target = "photoshop";
           bt.body = save_to_psd_function.toSource()+"("+obj.toSource()+");";
           bt.onError = function(errObj) {
              // the next line display the error in the console
              $.writeln(errObj.body);
              // PROBLEM this error is never throw 
              throw new Error (errObj.body);
           };
           bt.send(100);
      }
      
      
      function save_to_psd_function(serializedObject){
          app.displayDialogs = DialogModes.NO;
          var obj = eval(serializedObject);
          var file_path = decodeURI(obj.file_path);
          // this will generate an exception
          //var img_file = new File(file_path);
          var ps_doc = app.open(img_file);
          psdSaveOption = new PhotoshopSaveOptions();
          psdSaveOption.embedColorProfile = true;
          app.activeDocument.saveAs(img_file, psdSaveOption, true, Extension.LOWERCASE);
          ps_doc.close();
          
          app.displayDialogs = DialogModes.ALL;
      }
      
      
        • 1. Re: use bridgeTalk with onError event, exception handling
          bastieneichenberger Level 1

          Hi all,

           

          I found this solution if it can be helpfull for someone.

          But I don't know if it is the better way. I'm not abable to run a new exception in the onResult function.

           

           

          function save_to_PSD(obj){
              var error = null;
              var bt = new BridgeTalk();
               bt.target = "photoshop";
               bt.body = save_to_psd_function.toSource()+"("+obj.toSource()+");";
               bt.onError = function(ex){
                  error = ex.body
               }
               bt.send(100);
               if(error != null){
                  throw new Error(error);
               }
          }