Is there a way to get try / catch to work with batchPlay code in UXP for Photoshop? I’ve tried it with several different batchPlay functions. In all cases I’ve tested, it doesn’t catch the error so it seems universal to batchPlay coding.
I tested with a couple of DOM items and try/catch works properly.
Just tested it, .catch() doesn’t seem to work, but .then() works and returns a descriptor including a message when there is an error: photoshop.app.batchPlay([__selectByIndex(2)], {}).then(e => console.log(e))
On your system, does the Photoshop popup error message still occur? Or do you get both the console log and the Photoshop message?
Any chance that you post your selectByIndex function too so I can test it exactly as you are? I’m not able to replicate this on my system. I thought I applied it correctly but I’m still getting a Photoshop error only but nothing in the logs.
I’ve never gotten any Photoshop error popup for bad batchplayCode yet At least as far as I remember. So I’m only seeing the error in the console, which I’m actively logging.
Just had a chance to test and I could repeat your results with your functions. However, when using my select by layer name function, the error would pop up in Photoshop and not appear in the descriptor in the log.
I figured out that the options key needs to be removed from the descriptor. Without the options key it will show the error in the log. With the option key, the error message pops up in Photoshop and doesn’t show in the log.
Just FYI in case anyone needs the info… This works to skip the Photoshop error message and return it using .then.
I could do with some clarification on this please.
From a button on the plugin I am selecting a Brush Preset.
All works fine if the Brush Preset is present but if the Brush Preset is not there then obviously it fails and I get a Photoshop Error Message Box.
Ideally, I would have liked to catch this error and show my own Error Message but I dont think this is possible.
This is the code I am using to select the Brush Preset
does stop the Photoshop Error Box from showing and yes, I can confirm it does on my system. I am not sure what this code actually does and could it have any negative impact by removing it ?.
The dialogOptions are probably related to the DialogModes setting from Extendscript:
I haven’t seen anything in the API about this though. Ironically, it’s doing the exact opposite of what it’s supposed to do - “dontDisplay” should suppress dialogues as one might expect, however it actually shows them until the code gets removed. I don’t include this option in any of my Descriptors.
Anyways, you could prevent the error from occurring, if you check if the brush preset exists before selecting it. You’ll probably find it in the Application Descriptor