Skip to content

Commit 292661b

Browse files
committed
refactor: replace general Exceptions by specific ones
1 parent 734250e commit 292661b

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

at.siemens.ct.jminizinc.diag.ui/src/main/java/at/siemens/ct/jmz/ui/TextComponentLogger.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright Siemens AG, 2016
2+
* Copyright Siemens AG, 2016-2017
33
*
44
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
55
* If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -15,8 +15,8 @@
1515
import java.util.SortedMap;
1616
import java.util.TreeMap;
1717

18-
import at.siemens.ct.jmz.diag.DiagnosisMetadata;
1918
import at.siemens.ct.jmz.diag.DiagnoseProgressCallback;
19+
import at.siemens.ct.jmz.diag.DiagnosisMetadata;
2020
import at.siemens.ct.jmz.elements.constraints.Constraint;
2121

2222
/**
@@ -148,8 +148,8 @@ public void displayFile(String fileName) {
148148
}
149149

150150
@Override
151-
public void displayPartOfDiagnosis(List<Constraint> diagnose, List<Constraint> inputConflictSet, String message,
152-
String indent) throws Exception {
151+
public void displayPartOfDiagnosis(List<Constraint> diagnose, List<Constraint> inputConflictSet, String message,
152+
String indent) {
153153
// TODO Auto-generated method stub
154154
StringBuilder stringBuilder = new StringBuilder();
155155
displayInputSet(inputConflictSet, message);
@@ -203,25 +203,25 @@ public void diagnosisFound(List<Constraint> diagnosis, List<Constraint> inputCon
203203

204204
}
205205

206-
private String trimLevel(String message) throws Exception {
206+
private String trimLevel(String message) {
207207
int paranthesisIndex = 0;
208208
if (message != null && !message.isEmpty()) {
209209
paranthesisIndex = message.indexOf(")");
210210
}
211211
if (paranthesisIndex < 0) {
212-
throw new Exception(String.format("Message %s do not contains \\')\\' ", message));
212+
throw new IllegalArgumentException(String.format("Message %s do not contains \\')\\' ", message));
213213
}
214214

215215
return message.substring(paranthesisIndex + 1, message.length());
216216
}
217217

218-
private String getLevel(String message) throws Exception {
218+
private String getLevel(String message) {
219219
int paranthesisIndex = 0;
220220
if (message != null && !message.isEmpty()) {
221221
paranthesisIndex = message.indexOf(")");
222222
}
223223
if (paranthesisIndex < 0) {
224-
throw new Exception(String.format("Message %s do not contains \\')\\' ", message));
224+
throw new IllegalArgumentException(String.format("Message %s do not contains \\')\\' ", message));
225225
}
226226

227227
return message.substring(0, paranthesisIndex + 1).trim();

at.siemens.ct.jminizinc.diag.ui/src/main/java/at/siemens/ct/jmz/ui/VariableDialog.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.awt.event.WindowAdapter;
2323
import java.awt.event.WindowEvent;
2424
import java.io.File;
25+
import java.io.IOException;
2526
import java.util.ArrayList;
2627
import java.util.Collections;
2728
import java.util.List;
@@ -64,7 +65,7 @@ public class VariableDialog {
6465
private final String FAST_DIAG_ALL = "FastDiag - all minimal diagnoses";
6566
private final String FAST_DIAG = "FastDiag - first minimal diagnosis";
6667

67-
public VariableDialog(File mznFile) throws Exception {
68+
public VariableDialog(File mznFile) throws IOException {
6869
VariableDialog.mznFile = mznFile;
6970
mznCp = new MiniZincCP(mznFile);
7071
decisionVariables = mznCp.getElementsFromFile();
@@ -92,7 +93,7 @@ public static void main(String[] args) {
9293
if (args.length > 0) {
9394
mznpath = args[0];
9495
} else {
95-
FileChooserDialog fcd = new FileChooserDialog();
96+
FileChooserDialog fcd = new FileChooserDialog();
9697
mznpath = fcd.getFile();
9798
}
9899

@@ -224,7 +225,7 @@ private void displayDecisionVariables() {
224225
controlPanel.add(scrollPane);
225226
}
226227

227-
private List<Constraint> getAllValuesFromTheInterface() throws Exception {
228+
private List<Constraint> getAllValuesFromTheInterface() {
228229

229230
ArrayList<Constraint> userConstraints = new ArrayList<Constraint>();
230231

at.siemens.ct.jminizinc.diag.ui/src/test/java/at/siemens/ct/jmz/mznparser/TestMznParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright Siemens AG, 2016
2+
* Copyright Siemens AG, 2016-2017
33
*
44
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
55
* If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -10,6 +10,7 @@
1010
import static org.junit.Assert.assertTrue;
1111

1212
import java.io.File;
13+
import java.io.IOException;
1314
import java.util.regex.Matcher;
1415
import java.util.regex.Pattern;
1516

@@ -24,14 +25,14 @@
2425
import at.siemens.ct.jmz.expressions.set.RangeExpression;
2526

2627
/**
27-
* @author Copyright Siemens AG, 2016
28+
* @author Copyright Siemens AG, 2016-2017
2829
*/
2930
public class TestMznParser {
3031

3132
MiniZincCP constraintProblem;
3233

3334
@Test
34-
public void testMznParser() throws Exception {
35+
public void testMznParser() throws IOException {
3536
File miniZincFile = new File("src/test/java/testConflictDetection4.mzn");
3637
constraintProblem = new MiniZincCP(miniZincFile);
3738
int noOfVar = constraintProblem.getElementsFromFile().size();

0 commit comments

Comments
 (0)