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 173 views
173 views asked Jul 11, 2022 by avibootz
1 answer 204 views
204 views asked Apr 3, 2021 by avibootz
2 answers 297 views
1 answer 216 views
1 answer 196 views
196 views asked Dec 17, 2016 by avibootz
1 answer 201 views
201 views asked Dec 17, 2016 by avibootz
1 answer 217 views
...