Encountering a similar issue recently made me realize that the try/catch block is not necessary in Protractor. Instead, you can implement error handling like this:
try {
loadWebApp();
login();
openUserPreferences();
changePassword();
} catch (err) {
console.error(
"An error was thrown! " + err);
}
loadWebApp().
then(login).
then(openUserPreferences).
then(changePassword).
then(null, function(err) {
console.error(
"An error was thrown! " + err);
});
You can find more information on this approach at: https://code.google.com/p/selenium/wiki/WebDriverJs#Promises
under Value Propagation and Chaining
To reiterate, there's no need for a traditional try/catch block.
In essence, this method works because
a promise can either be RESOLVED or REJECTED and in case of a rejected or failed promise, this line [ then(null, function(err) { ... } ] will act as the CATCH block.
It's important to note that the then(null, function(err))( does not require a callback but only an errBack; indicating that we are only concerned with failures and not with successful resolution, hence the NULL for callback and the function(error) for the errBack.
No need to wrap this in a try/catch and throw the error as suggested previously in the accepted answer (@Eitan Peer).
Hopefully, this explanation proves beneficial to those grappling with Protractor challenges, much like I did.