Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Check for an invalid Object

  • Check for an invalid Object

    Posted by Terje Lundgren on June 6, 2020 at 1:27 pm

    Is there a best practice to check if an object is invalid without halting execution?

    var c = app.project.activeItem;
    var a = c.layer(1); // "[object AVLayer]"
    a.remove(); // Object is invalid
    //Trying to access a property known not to exist:
    a.name // "Unable to execute script at line 1."
    Using try/catch is the only way I have found to work:
    try { a.name } catch (err) {
    alert("ReferenceError ignored");
    // ...
    }

    Terje Lundgren replied 5 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    June 6, 2020 at 3:52 pm

    I think isValid() does what you want:


    var c = app.project.activeItem;
    var a = c.layer(1); // "[object AVLayer]"
    a.remove();
    if (isValid(a)){
    alert(a.name);
    }else{
    // do something else
    }

    Dan

  • Terje Lundgren

    June 7, 2020 at 5:38 am

    It does indeed. Thanks Dan!

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