Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * class untuk handling exception menggunakan try, catch, dan throw
- *
- * @author Dwinanda Bagoes Ansori
- * @version 29 Desember 2020
- */
- import java.util.Scanner;
- public class ThrowTest
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- int komodo;
- System.out.println("Bro tolong angkat komodo ke truk dong, truknya cukup 4 komodo bro");
- System.out.println();
- try
- {
- System.out.print("Jumlah komodo yang diangkat : ");
- komodo = input.nextInt();
- if (komodo > 4)
- {
- throw new Exception("waduh kelebihan bro, gacukup truknya");
- }
- else
- {
- System.out.println("Yoi mantap cukup bro");
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment