better error handling

This commit is contained in:
rusefi 2017-03-03 20:08:41 -05:00
parent 653bd69131
commit fa7a8dcf7a
3 changed files with 12 additions and 4 deletions

View File

@ -209,12 +209,13 @@ public class ECUEditor {
Rom rom;
try {
rom = new DOMRomUnmarshaller().unmarshallXMLDefinition(doc.getDocumentElement(), romContent, editor.getStatusPanel());
} catch (RomNotFoundException e) {
throw new IllegalStateException("While reading " + romDefinitionFile.getName(), e);
} finally {
// Release mem after unmarshall.
parser.reset();
doc.removeChild(doc.getDocumentElement());
fileStream.close();
System.gc();
}
return rom;
}

View File

@ -32,6 +32,7 @@ import javax.management.modelmbean.XMLParseException;
import javax.naming.NameNotFoundException;
import javax.swing.JOptionPane;
import com.rusefi.FileLog;
import com.rusefi.Launcher;
import org.apache.log4j.Logger;
import org.w3c.dom.Node;
@ -69,6 +70,7 @@ public final class DOMRomUnmarshaller {
this.progress = progress;
Node n;
NodeList nodes = rootNode.getChildNodes();
String romIdString = "(none)";
// unmarshall scales first
for (int i = 0; i < nodes.getLength(); i++) {
@ -96,6 +98,10 @@ public final class DOMRomUnmarshaller {
RomID romID = unmarshallRomID(n2, new RomID());
romIdString = romID.getInternalIdString();
FileLog.MAIN.logLine("Looking for " + romIdString);
if (romID.getInternalIdString().length() > 0
&& foundMatch(romID, romContent)) {
Rom output = unmarshallRom(n, new Rom());
@ -110,7 +116,7 @@ public final class DOMRomUnmarshaller {
}
}
}
throw new RomNotFoundException();
throw new RomNotFoundException("Match not found for " + romIdString);
}
public static boolean foundMatch(RomID romID, byte[] file) {
@ -278,7 +284,7 @@ public final class DOMRomUnmarshaller {
}
}
}
throw new RomNotFoundException();
throw new RomNotFoundException("xmlID=" + xmlID);
}
public RomID unmarshallRomID(Node romIDNode, RomID romID) {

View File

@ -23,6 +23,7 @@ public final class RomNotFoundException extends Exception {
private static final long serialVersionUID = -5434546006966986885L;
public RomNotFoundException() {
public RomNotFoundException(String msg) {
super(msg);
}
}