Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserException
- {
- public static void main(String args[])
- {
- check(5);
- check(11);
- }
- static void check(int a)
- {
- try
- {
- if(a>10)
- {
- throw new MyException(a);
- }
- else
- {
- System.out.println(a);
- }
- }
- catch(MyException e)
- {
- System.out.println(e);
- }
- }
- }
- class MyException extends Exception
- {
- int num;
- MyException(int a)
- {
- num = a;
- }
- public String toString()
- {
- String s = num + "Can't be greater than 10";
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment