Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
2 of 5
edited title
BuZZ-dEE

Difference between Return Error and throw Error

I found the following code in a project, that I do not understand.:

get(key, store = null) {
    if (!key) {
      return new Error('There is no key to get!');
    }

    let dbstore = this.localforage;

    if (store !== null) {
      dbstore = store;
    }

    return dbstore
      .getItem(key)
      .then(function(value) {
        return value;
      })
      .catch(function(err) {
        return new Error('The key (' + key + ") isn't accessible: " + err);
      });
  }

Why return new Error('There is no key to get!'); instead of throw new Error('There is no key to get!');?

Also why not throw an error in the catch block?

BuZZ-dEE
lang-js