Browse Source

Missing try/catch around parseInt call

Patrick Falls 12 years ago
parent
commit
eea89c7166
1 changed files with 14 additions and 7 deletions
  1. 14 7
      restexpress/src/main/java/hello/controller/MysqlController.java

+ 14 - 7
restexpress/src/main/java/hello/controller/MysqlController.java

@@ -35,16 +35,23 @@ public class MysqlController
 
 		// Get the count of queries to run.
 		int count = 1;
-		count = Integer.parseInt(request.getHeader("queries"));
-
-		// Bounds check.
-		if (count > 500)
+		try
 		{
-			count = 500;
+			count = Integer.parseInt(request.getHeader("queries"));
+		
+			// Bounds check.
+			if (count > 500)
+			{
+				count = 500;
+			}
+			if (count < 1)
+			{
+				count = 1;
+			}
 		}
-		if (count < 1)
+		catch(NumberFormatException nfexc)
 		{
-			count = 1;
+			// do nothing
 		}
 
 		// Fetch some rows from the database.