Last active
November 18, 2015 20:16
-
-
Save AnnaBoro/9baa7c6269cbf992d929 to your computer and use it in GitHub Desktop.
exception
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson6; | |
public class ExceptionFrame9 { | |
public static void main(String[] args) { | |
ExceptionFrame9 ex = new ExceptionFrame9(); | |
System.out.println(ex.doDivision(2, 0)); | |
System.out.println(ex.doDivision(3, 8)); | |
try { | |
ex.toRetire(-2); | |
ex.toRetire(5); | |
ex.toRetire(70); | |
} | |
catch (MyPersonalException e) { | |
e.printStackTrace(); | |
} | |
} | |
public double doDivision(int a, int b) { | |
int c = 0; | |
try { | |
c = a / b; | |
System.out.println("turn oven on"); | |
} | |
catch (ArithmeticException e) { | |
System.out.println("division by zero is not allowed"); | |
} | |
finally { | |
System.out.println("turn oven off)"); | |
} | |
return c; | |
} | |
public void toRetire(int age) throws MyPersonalException{ | |
if (age < 0) { | |
throw new MyPersonalException(); | |
} | |
else if (age > 65) { | |
System.out.println("Welcome to retire"); | |
} | |
else System.out.println("Work a little more"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson6; | |
public class MyPersonalException extends Exception { | |
public MyPersonalException() { | |
} | |
@Override | |
public void printStackTrace() { | |
System.out.println("Enter the correct age"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment