My javascript Altus program crashes. In the F12 console I see the engine is throwing an exception. Why?

0 votes
asked May 10, 2022 by ba3user (4,000 points)
What is going on? Why is Altus throwing an exception?

1 Answer

0 votes
answered May 10, 2022 by ba3user (4,000 points)

In most cases here is the sequence of events that causes this to happen:

  1. Your javascript code is executing inside a delegate 
  2. The delegate code that is running has a problem

In a "normal" program (one without a delagate), let's say that you call a function and the function name is misspelled, or the function is missing altogether. In the F12 console window, you will get a message to this effect and it is easy to fix the problem.

But in the case of a delegate (for example, a delegate that handles marker clicks), a call to a missing function will cause the engine to throw an exception. 

The easiest way to track down the problem is to look at the message with the thrown exception in the F12 console - it will usually name the missing function. If not, use console.log statements to find exactly where the code calls it quits. Almost always, you will find something like a misspelled function name or some other trivial problem like that. 

If you take one of the jsfiddle examples that uses extensive delegate code (e.g., you can create this kind of error by removing or misspelling one of the functions called by the delegate, e.g. addTextLabelToMarker. When you run the code, you will see what the exception looks like.