I use chrome.fileSystem API in my app to open a file. When I click the Cancel button of the file chooser dialog, an error occurs:
For this type of errors try catch won't be helpful. Instead you can access the global variable chrome.runtime.lastError as @xan mentioned in his awesome response above(by the way you should read it and upvote it!).
Now, here I provide an example that can be used:
function catchLastError(){
if(chrome.runtime.lastError){
console.log("error: ", chrome.runtime.lastError);
}else{
// some code goes here.
}
}
chrome.fileSystem.chooseEntry(yourEntry,catchLastError);