JavaScript: My try/catch is being skipped… any thoughts?

Sep 13, 2010 at 4:11am

JavaScript: My try/catch is being skipped… any thoughts?

Hello,

First off I’m a little new to JavaScript so I may be missing something here. Here is a sample piece of code where I’m just trying out the try/catcch and my catch is never called/caught.

I have a genaric function where I setup a callback for watching a property.

[---code---]
try
{
Param = new LiveAPI
(this.patcher,
PropertyChangeCallback,
“id ” + LiveObjID);

if (!Param)
{
post(“n*****FAILED to create Param callback…*****”);
return;
}

Param.property = PropertyToTrack;
post(“n–: Param to tracck:”,Param.property);
}
catch (e)
{
post(“n*** property error:”,e.exception_var );
}
[---end code---]

Any thoughts would be greatly appreciated.

Thanks,
Brett

#52287
Sep 13, 2010 at 5:37pm

Hi Brett,

I’ve played a bit with your code and this is my source:

autowatch = 1;

function main()
{
    //PropertyToTrack = "42";
    try
    {
        Param = new LiveAPI(this.patcher, PropertyChangeCallback, "live_set");

        if (!Param)
        {
            post("n*****FAILED to create Param callback...*****");
            return;
        }

        post("Param is ok");

        Param.property = PropertyToTrack;
        post("n--: Param to tracck:", Param.property);
    }
    catch (e)
    {
        post("n*** property error:", e.exception_var );
    }
}

function PropertyChangeCallback()
{
    post("inside PropertyChangeCallback");
    post();

    return;
}

This will catch an exception because PropertyToTrack is not defined. If you un-comment //PropertyToTrack = “42″; then it will work fine, without causing an exception. The LiveAPI path is called by name in the examples I’ve seen. That makes sence because the id is created on the fly and can be different on another run.

#187904
Sep 16, 2010 at 3:34pm

hello,

My issue is not the Id but actually an issue where if I send in a property that cannot be listened to I get an error in the debug window saying something close to “this property cannot be listened to.”. Am I missing something there as I would expect it to work the same way?

Thanks,
Brett

#187905

You must be logged in to reply to this topic.