Global error handler not catching errors in methods

I have setup a global error handler that is fine catching errors in lifecycle hooks but if I throw errors from methods the error goes uncaught.

Shouldn’t a global even handler catch all errors? Am I missing something to catch errors from methods.

Please provide an example.

Well I have a method to check a string is of a certain length in a components

so my method

methods: {
   checkString() {
    if(this.string < 6) {
     throw new Error('string not long enough');
    }
  }
}

in the console the method is uncaught

but if I in the mounted life cycle hook I just force an error

mounted() {
 if(true) {
  throw new Error('i can see you');
 }
}

my error handler will catch this

my error handler is made global through a plugin

export default ({ Vue }) => {

  Vue.config.errorHandler = (err, vm = new Vue(), info) => {
    console.log('trace start');
    console.log(err);
    console.log(vm);
    console.log(info);
    console.log('trace end');
  };
};

How do you call the method?

checkString() is called by an @click on a button in the component template

Could u solve this issue? Struggling for the same usecase…

Hi @jkirkby91-2

You can try these 2 ways:
1st Way:

methods: {
   checkString() {
    if(this.string.length < 6) {
     throw new Error('string not long enough');
    }
  }
}

2nd Way:

methods: {
   checkString() {
    if(true) {
     throw new Error('string not long enough');
    }
  }
}

Hope this helps!!