Answers for "how to throw a java exceptions"

7

throw io exception java

public static void foo() throws IOException {
    // some code here, when something goes wrong, you might do:
    throw new IOException("error message");
}

public static void main(String[] args) {
    try {
        foo();
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
}
Posted by: Guest on July-15-2020
3

how do you handle exceptions in java

I use try & catch blocks to handle any exceptions in my code. 
  I am familiar with major checked and unchecked exceptions and 
  handle it accordingly to make my code execution smooth
Posted by: Guest on November-28-2020

Code answers related to "how to throw a java exceptions"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language