How to use try, catch, exceptions in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

             int n = 1 / 0;
             
             System.out.println(n);

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

/*
                   
run:
      
java.lang.ArithmeticException: / by zero
          
 */

 



answered Dec 17, 2016 by avibootz

Related questions

1 answer 212 views
2 answers 295 views
2 answers 359 views
2 answers 427 views
1 answer 247 views
1 answer 216 views
1 answer 169 views
169 views asked Jul 11, 2022 by avibootz
...