Answer the question
In order to leave comments, you need to log in
What is the best way to catch errors inside Object.observe()?
Hello.
Errors inside Object.observe() are not displayed to the console, and if you wrap the insides of the callback function in try...catch , then these errors are caught, but without stopping the code execution.
Example without try...catch :
var test = [0,1];
function observer(){
'use strict';
a = 0; // должно вызвать ошибку
}
Object.observe(test, observer);
test.push(2); // не вызовет ошибку
var test = [0,1];
function observer(){
'use strict';
try {
a = 0; // должно вызвать ошибку
} catch (error) {
console.error(error)
}
}
observer() // вызовет сообщение console.error(error)
Object.observe(test, observer);
test.push(2); // вызовет сообщение console.error(error)
Answer the question
In order to leave comments, you need to log in
I found a commit on the topic: https://github.com/v8/v8/commit/db0a63d2c08a2404a8... → the bug report was back in January 2014: https://code.google.com/p/chromium/issues/detail?i ...
I think in the near future this problem will not become.
The observer function is executed asynchronously and, accordingly, does not cause the synchronous code to stop.
Google debugging errors in asynchronous code, as I don't understand exactly what you want to achieve. Would Node.js - would advise domains. Promises are poorly suited for debugging errors in events.
If you want something similar, but synchronously - try Proxy . Although they are completely raw, they are far from always suitable for the key.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question