Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MojWyjatek extends Exception {
- public MojWyjatek(){
- super();
- }
- public MojWyjatek(String przyczyna){
- super();
- System.out.println("Wystapił wyjątek a przyczyna to "+przyczyna);
- }
- }
- public class Gra{
- public int dodaj(int a,int b) throws MojWyjatek{
- if (a+b>10) throw new MojWyjatek("za dużo");
- return a+b;
- }
- public static void main(String [] args) {
- int a=10;
- int b=12;
- Gra game=new Gra();
- try {
- game.dodaj(a,b);
- } catch (MojWyjatek e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment