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 301 views
2 answers 423 views
2 answers 502 views
2 answers 548 views
1 answer 331 views
1 answer 299 views
1 answer 277 views
277 views asked Jul 11, 2022 by avibootz
...