Skip to content

Commit 3e31921

Browse files
committed
Removed try catch and set to throw the exception
1 parent 8fb51bd commit 3e31921

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

‎printscreen/src/main/java/org/baeldung/corejava/Screenshot.java‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@ public Screenshot(String filePath, String filenamePrefix,
2020
this.timeToWait = timeToWait;
2121
}
2222

23-
public void getScreenshot() {
24-
try {
25-
Thread.sleep(timeToWait);
26-
Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
27-
Robot robot = new Robot();
28-
BufferedImage img = robot.createScreenCapture(rectangle);
29-
ImageIO.write(img, fileType, setupFileNamePath());
30-
} catch (Exception ex) {
31-
System.out.println("Error occurred while getting the Print Screen.");
32-
}
23+
public void getScreenshot() throws Exception {
24+
Thread.sleep(timeToWait);
25+
Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
26+
Robot robot = new Robot();
27+
BufferedImage img = robot.createScreenCapture(rectangle);
28+
ImageIO.write(img, fileType, setupFileNamePath());
3329
}
3430

3531
private File setupFileNamePath() {

0 commit comments

Comments
 (0)