Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions AE Script: try…catch not working

  • AE Script: try…catch not working

    Posted by Chris Keller on May 16, 2009 at 12:45 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

    David Cabestany replied 12 years, 8 months ago 4 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    May 16, 2009 at 5:22 pm

    I get the same result. It is strange.

    Dan

  • Chris Keller

    May 17, 2009 at 2:14 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…

  • Dan Fredley

    August 15, 2012 at 6:59 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();
    }

  • David Cabestany

    September 17, 2013 at 9:42 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);

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy