Browse Source

explicit.DTMSimple: use auto-close in buildFromPrismExplicit(), better error message (with Steffen Maercker)

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11731 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Joachim Klein 9 years ago
parent
commit
edbb99fdb4
  1. 12
      prism/src/explicit/DTMCSimple.java

12
prism/src/explicit/DTMCSimple.java

@ -136,19 +136,16 @@ public class DTMCSimple extends DTMCExplicit implements ModelSimple
@Override
public void buildFromPrismExplicit(String filename) throws PrismException
{
BufferedReader in;
String s, ss[];
int i, j, n, lineNum = 0;
double prob;
try {
// Open file
in = new BufferedReader(new FileReader(new File(filename)));
// Open file for reading, automatic close when done
try (BufferedReader in = new BufferedReader(new FileReader(new File(filename)))) {
// Parse first line to get num states
s = in.readLine();
lineNum = 1;
if (s == null) {
in.close();
throw new PrismException("Missing first line of .tra file");
}
ss = s.split(" ");
@ -170,11 +167,8 @@ public class DTMCSimple extends DTMCExplicit implements ModelSimple
s = in.readLine();
lineNum++;
}
// Close file
in.close();
} catch (IOException e) {
System.out.println(e);
System.exit(1);
throw new PrismException("File I/O error reading from \"" + filename + "\": " + e.getMessage());
} catch (NumberFormatException e) {
throw new PrismException("Problem in .tra file (line " + lineNum + ") for " + getModelType());
}

Loading…
Cancel
Save