You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log("Error on ", e.lineNumber, e.instruction);
436
+
}
437
+
438
+
try {
439
+
machine.nextStep();
440
+
machine.nextStep();
441
+
} catch(e) {
442
+
// do whatever with the error
443
+
}
444
+
```
445
+
446
+
As shown above, in order to use it, you are required to pass a callback. The callback will be called with the same fields that `getTable` fetches. The important thing to note here is that once the machine executes the program completely, the callback will no longer be called no matter how many times you call `nextStep`.
447
+
448
+
This manner of execution is very useful to debug things like infinite loops.
449
+
409
450
### Error Handling
410
451
411
-
All errors currently are encapsulated by the `InvalidInstructionException` class. All exceptions have two pieces of information currently.
452
+
All errors currently are encapsulated by the `InvalidInstructionException` class. All exceptions have two pieces of information currently.
412
453
413
-
1. Source line number where the exception occurred in `lineNumber`
414
-
2. The offending instruction in `instruction`
454
+
1. Source line number where the exception occurred in `lineNumber`
455
+
2. The offending instruction in `instruction`
415
456
416
-
Always surround your machine's `load` and `execute` in try catch blocks.
457
+
Always surround your machine's `load` and `execute` in try catch blocks.
417
458
418
-
```javascript
419
-
try {
420
-
machine.load(program);
421
-
machine.execute();
422
-
} catch(e) {
423
-
console.log("Error on ", e.lineNumber, e.instruction);
424
-
}
425
-
```
459
+
```javascript
460
+
try {
461
+
machine.load(program);
462
+
machine.execute();
463
+
} catch(e) {
464
+
console.log("Error on ", e.lineNumber, e.instruction);
0 commit comments