Skip to content
Snippets Groups Projects
Commit 9d0ac87a authored by hansen's avatar hansen
Browse files

updated exception handler

parent 372986ec
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,7 @@ public class ExpressionTranslator implements SyntaxTreeConstants { ...@@ -46,7 +46,7 @@ public class ExpressionTranslator implements SyntaxTreeConstants {
this.translator = translator; this.translator = translator;
} }
public void parse() { public void parse() throws de.tla2b.exceptions.FrontEndException {
String dir = System.getProperty("java.io.tmpdir"); String dir = System.getProperty("java.io.tmpdir");
ToolIO.setUserDir(dir); ToolIO.setUserDir(dir);
...@@ -66,7 +66,9 @@ public class ExpressionTranslator implements SyntaxTreeConstants { ...@@ -66,7 +66,9 @@ public class ExpressionTranslator implements SyntaxTreeConstants {
fw.write(module); fw.write(module);
fw.close(); fw.close();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Can not create file temporary file in directory '" + dir + "'"); throw new de.tla2b.exceptions.FrontEndException(
"Can not create file temporary file in directory '" + dir
+ "'");
} }
SpecObj spec = parseModuleWithoutSemanticAnalyse(moduleName, module); SpecObj spec = parseModuleWithoutSemanticAnalyse(moduleName, module);
...@@ -96,8 +98,7 @@ public class ExpressionTranslator implements SyntaxTreeConstants { ...@@ -96,8 +98,7 @@ public class ExpressionTranslator implements SyntaxTreeConstants {
fw.close(); fw.close();
tempFile.deleteOnExit(); tempFile.deleteOnExit();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); throw new de.tla2b.exceptions.FrontEndException(e.getMessage());
throw new RuntimeException(e.getMessage());
} }
ToolIO.reset(); ToolIO.reset();
...@@ -107,7 +108,7 @@ public class ExpressionTranslator implements SyntaxTreeConstants { ...@@ -107,7 +108,7 @@ public class ExpressionTranslator implements SyntaxTreeConstants {
try { try {
moduleNode = parseModule(moduleName, sb.toString()); moduleNode = parseModule(moduleName, sb.toString());
} catch (de.tla2b.exceptions.FrontEndException e) { } catch (de.tla2b.exceptions.FrontEndException e) {
throw new RuntimeException(e.getLocalizedMessage()); throw new de.tla2b.exceptions.FrontEndException(e.getLocalizedMessage());
} }
} }
...@@ -154,19 +155,17 @@ public class ExpressionTranslator implements SyntaxTreeConstants { ...@@ -154,19 +155,17 @@ public class ExpressionTranslator implements SyntaxTreeConstants {
SANY.frontEndMain(spec, moduleName, ToolIO.out); SANY.frontEndMain(spec, moduleName, ToolIO.out);
} catch (FrontEndException e) { } catch (FrontEndException e) {
// Error in Frontend, should never happens // Error in Frontend, should never happens
return null; throw new de.tla2b.exceptions.FrontEndException(
"Frontend error! This should never happen.", spec);
} }
if (spec.parseErrors.isFailure()) { if (spec.parseErrors.isFailure()) {
// String[] m = ToolIO.getAllMessages();
String message = module + "\n\n" + spec.parseErrors; String message = module + "\n\n" + spec.parseErrors;
// System.out.println(spec.parseErrors);
message += allMessagesToString(ToolIO.getAllMessages()); message += allMessagesToString(ToolIO.getAllMessages());
throw new de.tla2b.exceptions.FrontEndException(message, spec); throw new de.tla2b.exceptions.FrontEndException(message, spec);
} }
if (spec.semanticErrors.isFailure()) { if (spec.semanticErrors.isFailure()) {
// String[] m = ToolIO.getAllMessages();
String message = module + "\n\n" + spec.semanticErrors; String message = module + "\n\n" + spec.semanticErrors;
message += allMessagesToString(ToolIO.getAllMessages()); message += allMessagesToString(ToolIO.getAllMessages());
throw new de.tla2b.exceptions.FrontEndException(message, spec); throw new de.tla2b.exceptions.FrontEndException(message, spec);
......
...@@ -357,7 +357,12 @@ public class Translator implements TranslationGlobals { ...@@ -357,7 +357,12 @@ public class Translator implements TranslationGlobals {
public static Start translateTlaExpression(String tlaExpression) { public static Start translateTlaExpression(String tlaExpression) {
ExpressionTranslator expressionTranslator = new ExpressionTranslator( ExpressionTranslator expressionTranslator = new ExpressionTranslator(
tlaExpression); tlaExpression);
try {
expressionTranslator.parse(); expressionTranslator.parse();
} catch (FrontEndException e) {
System.out.println(e.getMessage());
throw new RuntimeException();
}
expressionTranslator.translate(); expressionTranslator.translate();
return expressionTranslator.getBExpressionParseUnit(); return expressionTranslator.getBExpressionParseUnit();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment