Thursday, 14 October 2021

How to throw a javascript error during runtime via browser (Chrome)?

My objective: Test out my error handling functionality.

Temporary solution: Have a custom route: /error, which contains code which purposefully produces fatal error.

var a = undefined;
a.b.c // Breaks.

The above works, but I can't use it to test production site as the page is not required. I was looking for a way to test it via the browser. I tried simply adding" throw new Error("Custom error thrown here") to the console. That doesn't actually break it during runtime.

I tried adding a break point and adding the same code: throw new Error("Custom error thrown here"). That didn't work either.

Any other easier ways to do this rather than the above?

I was looking for a way where I can do it via browser only.

Thanks.



from How to throw a javascript error during runtime via browser (Chrome)?

No comments:

Post a Comment