Skip to main content
Inspiring
January 29, 2017
Answered

how to check and bypass an error in scripts....

  • January 29, 2017
  • 1 reply
  • 591 views

Hey guys, I've decided to go back and clean up some of the scripts that I use on a regular basis to make them more useful.
I'm sure this is a simple thing but I just don't know how to do it.

So I have a script to save out an image in various sizes/formats/whatever

Theres a specific error I encountered today in the following line of code:

activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);

After looking into it I found that if there aren't any transparent parts in my image then it stops right there and won't execute the rest of my script.
if I delete that line out it executes just fine.

I want to keep that line in my script for the instances when there are transparent pixels.
How would I go about checking to see if that line of code applies, and if it doesn't, then to simply skip over it and process the rest of the script without it?

This topic has been closed for replies.
Correct answer Chuck Uebele

Use a try/catch block:

try{

//your code here

}

catch(e){

//leave blank or enter code you want to run if it fails.

}

1 reply

Chuck Uebele
Chuck UebeleCorrect answer
Community Expert
January 29, 2017

Use a try/catch block:

try{

//your code here

}

catch(e){

//leave blank or enter code you want to run if it fails.

}

Inspiring
January 29, 2017

Perfect! it's so simple lol.

I'd seen those before in other scripts too but hadn't clicked that I could use it to simply block out a line if it didn't work.

Thanks man!

Chuck Uebele
Community Expert
January 29, 2017

Glad it was a simple fix.