diff --git a/modules/highgui/misc/java/src/java/highgui+HighGui.java b/modules/highgui/misc/java/src/java/highgui+HighGui.java index 7a25095166..e986618fb4 100644 --- a/modules/highgui/misc/java/src/java/highgui+HighGui.java +++ b/modules/highgui/misc/java/src/java/highgui+HighGui.java @@ -43,8 +43,7 @@ public final class HighGui { public static void imshow(String winname, Mat img) { if (img.empty()) { - System.err.println("Error: Empty image in imshow"); - System.exit(-1); + throw new IllegalArgumentException("Image is empty"); } else { ImageWindow tmpWindow = windows.get(winname); if (tmpWindow == null) { @@ -113,8 +112,7 @@ public final class HighGui { // If there are no windows to be shown return if (windows.isEmpty()) { - System.err.println("Error: waitKey must be used after an imshow"); - System.exit(-1); + throw new IllegalStateException("No windows created. Call imshow() first"); } // Remove the unused windows @@ -145,8 +143,7 @@ public final class HighGui { win.lbl.setIcon(icon); } } else { - System.err.println("Error: no imshow associated with" + " namedWindow: \"" + win.name + "\""); - System.exit(-1); + throw new IllegalStateException("No image set for window: \"" + win.name + "\". Call imshow() first"); } } @@ -158,6 +155,7 @@ public final class HighGui { } } catch (InterruptedException e) { e.printStackTrace(); + Thread.currentThread().interrupt(); } // Set all windows as already used