locked
Exception when use retrievePropertiesAsync method

    Question

  • Hi all,

    I am using retrievePropertiesAsync method in CP version. It's OK. But after upgrade to RTM version, it thrown exception "Exception was thrown at line 20, column 5 in Function code 0x8002802b - JavaScript runtime error: Element not found.". My code is below.

    function getFileProperties() {
        Windows.Storage.KnownFolders.picturesLibrary.getFileAsync("abc.xml").then(function (file) {
            file.getBasicPropertiesAsync().done(
                function (basicProperties) {
                    basicProperties.retrievePropertiesAsync(["System.Size"]).then(function (p) {
                        console.log("finish");
                    })
                });
        });
    }

    How do I fix it?

    Thanks,

    Vivian

    Thursday, August 23, 2012 10:54 AM

Answers

  • It is not an exception you need to worry about if there is no break in the execution.  That is what is called a handled exception.

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by Dino He Monday, September 24, 2012 3:16 AM
    Tuesday, August 28, 2012 12:11 PM
    Moderator

All replies

  • Hi Vivian,

    Did you look at the Migration Docs for CP to RP and RP to RTM (at the top of the forum)?

    What line is the failure on?

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, August 23, 2012 1:20 PM
    Moderator
  • Hi Jeft,

    This line basicProperties.retrievePropertiesAsync(["System.Size"]) throw exception. The app can continue run, but the exception thrown in the output window. I have a quick look at the Migration Docs, but I don't see any changes about that method. 

    Thanks,

    Vivian


    • Edited by Vivian Ng Thursday, August 23, 2012 5:26 PM more information
    Thursday, August 23, 2012 5:24 PM
  • Hi Vivian,

    This code did not work in CP.  CP did not have .done.

    The problem is not the API call but your usage of .done... it should be only used as the last item in the promise chain.

     

    You should do this:

     function getFileProperties() {
            
                Windows.Storage.KnownFolders.picturesLibrary.getFileAsync("abc.xml").then(function (file) {
                    file.getBasicPropertiesAsync().then(
                        function (basicProperties) {
                            basicProperties.retrievePropertiesAsync(["System.Size"]).done(function (p) {
                                console.log("finish");
                            })
                        });
                });
            
        }

    -Jeff 

    Jeff Sanders (MSFT)

    Friday, August 24, 2012 12:20 PM
    Moderator
  • Hi Jeft, Sory, I had a mistake. It work on RP version. I tried to change this code like you suggest but the exception still be thrown. So I think then or done is not the root cause. Thanks, Vivian
    Monday, August 27, 2012 11:04 AM
  • The code I posted works great for me.  There must be some other factor in your code or environment.  Try a different file, a blank application etc...  Make sure your app has Pictures capability checked in the manifest.

    Jeff Sanders (MSFT)

    Monday, August 27, 2012 11:37 AM
    Moderator
  • Hi Jeft,

    Did you open the Output window when run code? The app not crash when exception thrown, but if you open the Output window, you will see that. I tried a new blank application, but the result is the same. 

    Thanks,

    Vivian

    Monday, August 27, 2012 3:22 PM
  • I get to this line:

       console.log("finish");
    Do you?


    Jeff Sanders (MSFT)

    Monday, August 27, 2012 3:51 PM
    Moderator
  • Hi Jeft, Yes, I can get to that log. But on the Output window, I see this exception: "Exception was thrown at line 20, column 5 in Function code 0x8002802b - JavaScript runtime error: Element not found." How to avoid to receive this exception? Thanks, Vivian
    Tuesday, August 28, 2012 10:46 AM
  • It is not an exception you need to worry about if there is no break in the execution.  That is what is called a handled exception.

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by Dino He Monday, September 24, 2012 3:16 AM
    Tuesday, August 28, 2012 12:11 PM
    Moderator
  • Hi Jeft,

    I just afraid that exception will affect the performance of app.

    Thanks,

    Vivian

    Friday, August 31, 2012 10:54 AM