The reason it won’t catch anything in your example is because once the geocode()
callback is called, the try/catch
block is over. Therefore the geocode()
callback is executed outside the scope of the try
block and thus not catchable by it.
As far as I know, it is not possible to catch exceptions thrown in JavaScript callbacks (at least, not in any straightforward manner).