What is the output?
import java.io.IOException; public class Main { public static void main(String[] args) { int x = 10, y = 0, z = 0; try { z = x / y; } catch (IOException e) { // Handle exception } } }
} catch (IOException e) { //exception java.io.IOException is never thrown in body of corresponding try statement
If the code in a try block would not throw a checked exception and its associated catch blocks catch that exceptions, the compiler will generate an error.
Here is the fix
public class Main { public static void main(String[] args) { int x = 10, y = 0, z = 0; try {//w ww.j a va 2 s .co m z = x / y; } catch (Exception e) { // Handle the exception } } }