How to handle errors in the sampleTerrain callback?

Hello everyone,

I have this sandcastle sample:

I'd like to see the error message in the JS console. I haven't found documentation on how to handle the errors produced in the callback.

Could you help me please?
Thanks in advance!

b is undefined, so calling b.c throws an error message because you can’t read a property of undefined.

-Hannah

Yes, but the problem is, there should be an error appearing in the Javascript console, but it is never shown.

Maybe this example is more clear:

It obviosly has to crash on line 17, but the error doesn't appear in the console. It is a problem for me because it makes debugging hard. So the question is, can I handle it in some way?

Oh, sorry for misunderstanding your question.
The error is caught because it is happening inside the when callback. Here’s an example for how to handle errors with promises:

promise.then(function(updatedPositions) {
console.log(“message before the error”);

var a = b.c; // this should throw the error

console.log("message after the error");

}).otherwise(function(error) {
console.log(‘error handle here’);
});

``

Best,

Hannah

Thank you, Hannah! That's exactly what I was looking for.