ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

AE Script: try...catch not working

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Keller
AE Script: try...catch not working
on May 16, 2009 at 12:45:33 pm

Hey,

I get into a bizarre situation when developing/running scripts with "Enable JavaScript Debugger" on.

The very first time a script throws an error in a try...catch block, the debugger stops and jumps into the code instead of handling the error in the catch section. After skipping the runtime error, try...catch-handling works perfectly fine until I restart After Effects and run a script that throws an error. Then it's the same thing all over again: First time error - BAM - after this all's well.

For example, take this simple script:


try
{
var ob;
ob.expression = "COW";
}
catch(e) { alert ("Error Handling working."); }


The first time this code is executed, the debugger halts, telling me that "undefined is not an object". Any subsequent script that is launched handles errors correctly. BTW, "Do not break on Guarded Exceptions" is enabled.

Weird behavior... Any ideas? If not, it would be great if anyone could test the above script - maybe it's just my OS...

Thanks,
-Chris


Return to posts index

Dan Ebberts
Re: AE Script: try...catch not working
on May 16, 2009 at 5:22:05 pm

I get the same result. It is strange.

Dan



Return to posts index

Chris Keller
Re: AE Script: try...catch not working
on May 17, 2009 at 2:14:44 pm

"I get the same result. It is strange.
Dan "


It has to be a bug or something in the debugger, since without "Enable JavaScript Debugging" error handling works...


Return to posts index


Dan Fredley
Re: AE Script: try...catch not working
on Aug 15, 2012 at 6:59:18 am

I've been having this problem as well. I don't know if there's another way around it, but I put this at the beginning of my code:
var debugPref = app.preferences.getPrefAsLong("Main Pref Section", "Pref_JAVASCRIPT_DEBUGGER");
if(debugPref == 1) {
app.preferences.savePrefAsLong("Main Pref Section", "Pref_JAVASCRIPT_DEBUGGER", 0);
app.preferences.saveToDisk();
app.preferences.reload();
}

Then this at the end:
if (debugPref == 1) {
app.preferences.savePrefAsLong("Main Pref Section", "Pref_JAVASCRIPT_DEBUGGER", 1);
app.preferences.saveToDisk();
app.preferences.reload();
}


Return to posts index

David Cabestany
Re: AE Script: try...catch not working
on Sep 17, 2013 at 9:42:54 pm

Errrr, somewhat related, although much simpler (I think) thatn your original quesiton, but really really hoping that someone can help me.

I'm trying the expressions below and so far I haven't been able to do so, the try/catch reads the error message, but that's about it, I haven't been able to read the contents of my variable.

The second expression (Harry Frank's) it's returning the following errors:
Expected ;. Error occurred at line 1.

After I put the requested semicolon I get this:

Illegal use of reserved word. error occurred at line 3.

All I got at line 3 is the word else.

Weirdest of all is that I have used this expression in the past and it worked perfectly, in fact I just tried it in a different computer and it worked, both machines are running AE CS6 and are macs, the only difference is the offending one is running on Mountain Lion, whereas the one that worked is running on Snow Leopard.

If anyone can help me solve this would be enormously appreciated, I have over a 100 captions to deliver tomorrow.

Thanks,
David.

try
{
myPath="~/Desktop/captions.txt";
$.eval(thisComp.name)[0];
}
catch
(err)
{"missing";
}





if ($.os.indexOf("Mac") != -1)
myPath = "/Expressions/";
else
myPath = "file://c:Expressions";
myPath += "data.txt";
$.evalFile (myPath);
eval(thisComp.name);


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]