How to use try without a catch in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        try {  
            int n = 46;   
            System.out.println(n / 0);  
        }  
        finally {  
            System.out.println("finally");  
        }  
     }  
}



/*
run:

finally

Exception in thread "main" java.lang.ArithmeticException: / by zero
	at MyClass.main(MyClass.java:5)
	
*/

 



answered Oct 5, 2019 by avibootz

Related questions

1 answer 277 views
277 views asked Jul 11, 2022 by avibootz
1 answer 279 views
279 views asked Apr 3, 2021 by avibootz
2 answers 460 views
1 answer 303 views
1 answer 288 views
288 views asked Dec 17, 2016 by avibootz
1 answer 300 views
300 views asked Dec 17, 2016 by avibootz
1 answer 301 views
...