1

Actually my requirement is to highlight the block which has an error in its particular js functions.

We are developing the blocks using Blockly. Suppose I am applying one logic(functions) in Blocky, then that blocks will parse to js.

Then I need to execute the js step by step , while execution time. If any error occured in my logic(functions) I have to highlight that error in the blocks.

Is it possible to get the line number of the error?

Please look this link.

Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
bagya
  • 383
  • 1
  • 11
  • 38
  • This might be useful: http://stackoverflow.com/questions/1340872/how-to-get-javascript-caller-function-line-number-how-to-get-javascript-caller – stackErr Apr 26 '16 at 15:51

1 Answers1

0

I did something similar for my bachelor thesis. (I would share the thesis but since it's German i don't assume it would be of much help). There i generated PHP from Blocks, started it and then wanted to enable the user to step through the generated code block by block. The following isn't specific for Javascript so you might have to change some bits and pieces. Lets say the generated code looks similar to this:

codeGeneratedByFirstBlock();
codeGeneratedBySecondBlock();
codeGeneratedByThirdBlock();

My simple solution for tracking which Block is the actual block executed is to let My PHP codeGenerator generate slightly different code, when generating code for debugging:

setActualBlock(<idOfFirstBlock>);
codeGeneratedByFirstBlock();
setActualBlock(<idOfSecondBlock>)
codeGeneratedBySecondBlock();
setActualBlock(<idOfThirdBlock>)
codeGeneratedByThirdBlock();

The trick is, that the codeGenerator knows the id of the block it's generating code for. So let the Generator put this knowledge right in the code it's generating.

So when some of the codeGeneratedBy..Block() functions throws an exception, you would now know which block it corresponds to because you saved the lasts blocks id before. You might have to wrap codeGeneratedBy..Block() in a function, that catches Exceptions, continues normally when there is no exception but highlights the actual block when there is one.

There are some caveats anyway: This is good if you don't care about changing the generated code for debugging. That means the code isn't shown to the user or you don't care for the code to be "educational". There could also be problems when you have multi threaded code or callback code. When the callback is executed, you might have already called setActualBlockId() with another id that doesn't correspond to the block that generated the callback code.

Tinly
  • 21
  • 3