r/vuejs • u/gevorgter • 1d ago
Vue and JavaScript exceptions
Living on edge in 2026, asked claude to write some code. And end up with something like bellow.
Now i am thinking, do i really need this try/catch? What would be the consequence if i let the exception bubble up. Will VueJS handle it properly and i only need to configure app.config.errorHandler?
PS: Same goes for any exception thrown during IO which is more realistic than my example?
watch(selectedId, (id) => {
try {
localStorage.setItem(storageKey, String(id))
}
catch {
return
}
})
2
Upvotes
5
u/SonOfSofaman 1d ago
To test the behaviour of your system under error conditions, you can almost always generate an error intentionally. Get rid of the try/catch and temporarily insert
throw new Error("this is a simulated error")and see how it behaves. Then you'll know how your system behaves when a real exception occurs.6
u/CafeBagels08 1d ago
Just take a look at the documentation if you want to know what kind of exception you could run into: https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem
1
u/likeaffox 1d ago
No, the catch does nothing. If you were logging something or trying something else.
Edit looking at docs, you could ask the user for more storage, in the throw, but yeah this seem unnecessary