You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/06/09 15:54:59 UTC

[commons-math] 04/09: Throw named exceptions for IO errors

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 6d1351cc33f94c0f9595a37306359c2a04c6e00a
Author: aherbert <ah...@apache.org>
AuthorDate: Wed Jun 9 16:31:35 2021 +0100

    Throw named exceptions for IO errors
---
 .../commons/math4/examples/sofm/chineserings/StandAlone.java     | 9 +++++----
 .../org/apache/commons/math4/examples/sofm/tsp/StandAlone.java   | 9 +++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java b/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java
index ad827b0..1c53d10 100644
--- a/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java
+++ b/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java
@@ -17,8 +17,9 @@
 
 package org.apache.commons.math4.examples.sofm.chineserings;
 
-import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Callable;
 
@@ -76,9 +77,11 @@ public class StandAlone implements Callable<Void> {
      *
      * @param fileName File name.
      * @param sofm Classifier.
+     * @throws UnsupportedEncodingException If UTF-8 encoding does not exist.
+     * @throws FileNotFoundException If the file cannot be created.
      */
     private static void printResult(String fileName,
-                                    ChineseRingsClassifier sofm) {
+                                    ChineseRingsClassifier sofm) throws FileNotFoundException, UnsupportedEncodingException {
         final NeuronSquareMesh2D.DataVisualization result = sofm.computeQualityIndicators();
 
         try (final PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
@@ -91,8 +94,6 @@ public class StandAlone implements Callable<Void> {
             printImage("Topographic error", result.getTopographicError(), out);
             printImage("Normalized hits", result.getNormalizedHits(), out);
             printImage("U-matrix", result.getUMatrix(), out);
-        } catch (IOException e) {
-            // Do nothing.
         }
     }
 
diff --git a/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java b/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java
index 9e25a6c..2ad82b1 100644
--- a/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java
+++ b/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java
@@ -17,8 +17,9 @@
 
 package org.apache.commons.math4.examples.sofm.tsp;
 
-import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Callable;
 
@@ -142,10 +143,12 @@ public class StandAlone implements Callable<Void> {
      * @param fileName File.
      * @param travel Solution.
      * @param optimalDistance Length of shortest path.
+     * @throws UnsupportedEncodingException If UTF-8 encoding does not exist.
+     * @throws FileNotFoundException If the file cannot be created.
      */
     private static void printSummary(String fileName,
                                      City[] travel,
-                                     double optimalDistance) {
+                                     double optimalDistance) throws FileNotFoundException, UnsupportedEncodingException {
         try (final PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
             out.println("# Number of unique cities: " + City.unique(travel).size());
             out.println("# Travel distance: " + computeDistance(travel));
@@ -156,8 +159,6 @@ public class StandAlone implements Callable<Void> {
                 final double[] coord = c.getCoordinates();
                 out.println(coord[0] + " " + coord[1] + " # " + c.getName());
             }
-        } catch (Exception e) {
-            // Do nothing.
         }
     }
 }