Datasets:

ArXiv:
License:
File size: 503 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package exceptionexample3;
//negative number Exception
import java.util.Scanner;
public class Exception {

  
    public static void main(String[] args) {
        CheckNum obj=new CheckNum();
        Scanner scan=new Scanner(System.in);
        System.out.println("Enter any positive number:");
        int num=scan.nextInt();
        try{
            obj.checknumber(num);
        }
        catch(NegativeNumberException e){
          System.out.println("Exception caught!!"+e);
        }
    }
    
}