Skip to main content
bastieneichenberger
Inspiring
August 21, 2013
Question

use bridgeTalk with onError event, exception handling

  • August 21, 2013
  • 1 reply
  • 569 views

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;

}

This topic has been closed for replies.

1 reply

bastieneichenberger
Inspiring
August 22, 2013

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);

     }

}