From 2c9316c5fa0cc3e034fc9a4b6e3c6e0918f9b1df Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Thu, 16 Feb 2012 15:51:32 +0100 Subject: [PATCH] more informative error messages at simulation error --- .../apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java | 6 +++++- tools/cooja/java/se/sics/cooja/Simulation.java | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java index 73fb45907..f71d29fe2 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java @@ -335,7 +335,7 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc if (t < lastExecute) { throw new RuntimeException("Bad event ordering: " + lastExecute + " < " + t); } - + /* Execute MSPSim-based mote */ /* TODO Try-catch overhead */ try { @@ -345,6 +345,10 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc lastExecute = t; } catch (EmulationException e) { String stackTraceOutput = sendCLICommandAndPrint("stacktrace"); + if (stackTraceOutput == null) { + stackTraceOutput = ""; + } + stackTraceOutput = e.getMessage() + "\n\n" + stackTraceOutput; throw (ContikiError) new ContikiError(stackTraceOutput).initCause(e); } diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 6d01be202..972acda22 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -253,8 +253,8 @@ public class Simulation extends Observable implements Runnable { this.setChanged(); this.notifyObservers(this); + TimeEvent nextEvent = null; try { - TimeEvent nextEvent; while (isRunning) { /* Handle all poll requests */ @@ -289,7 +289,11 @@ public class Simulation extends Observable implements Runnable { /* Quit simulator if in test mode */ System.exit(1); } else { - GUI.showErrorDialog(GUI.getTopParentContainer(), "Simulation error", e, false); + String title = "Simulation error"; + if (nextEvent instanceof MoteTimeEvent) { + title += ": " + ((MoteTimeEvent)nextEvent).getMote(); + } + GUI.showErrorDialog(GUI.getTopParentContainer(), title, e, false); } } }