Skip to main content
Royi A
Inspiring
April 13, 2009
Question

How To Exit A Script?

  • April 13, 2009
  • 1 reply
  • 41856 views

Hello.

I'm trying to write a script (My First) for Photoshop.

I want to check a condition and if it's true to exit the script.

The problem I can't find any place writing what is the "Exit" command in a script.

Thanks.

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
April 13, 2009

Write your code in a function then you can test for your condition and use return to exit

function main(){

if(someThingIsWrong) return;

}

main();

Inspiring
April 13, 2009

Paul's advice is good. Two other techniques:

1) If you're deep down many levels of function calls, doing a simple return may not work. Use a 'throw' to bail out completely. If you don't want the user to see an error message, do a try/catch and see if the error is one you should ignore, one you should handle, or one you should let the user know about.

2) Hit ESC a bunch of times. Obviously, you can't do that from your script, but the user can do that from their keyboard.

-X

Inspiring
April 13, 2009

Hi X,

I understand how the call stack can effect an if(error) return statement but how do you use a try/catch to bail without the user seeing an error alert?

It seems to me that to stop the script you would have to re-throw an error inside the catch.