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 293 views
2 answers 415 views
2 answers 494 views
2 answers 543 views
1 answer 327 views
1 answer 294 views
1 answer 272 views
272 views asked Jul 11, 2022 by avibootz
...