Windows 8 adventures: error handling and the async pattern
What I didn’t mention at the time is that the then method expects three parameters (all functions). Besides the success function, you can also pass two other functions which will be called, respectively, for reporting an error and for reporting progress. If you follow my previous advice and return new Promises from the then method, then you can get “global” error handling by adding a final then method which defines the global method function. Here’s an improved version of the createFolderAndFile function:
Notice that there’s a slight change and we’re returning the result of the storeAsync().then call so that all eventual errors can be handled in the error function passed to the last then method call. You can test this behaviour by adding throw statements in several places in the previous code and by setting a breakpoint inside that anonymous error function.
And that’s all for now. Stay tuned for more.