Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn EXCEPTION HANDLING in 8 minutes! ⚠️
Play lesson

Java tutorial for beginners ☕ - Learn EXCEPTION HANDLING in 8 minutes! ⚠️

5.0 (4)
40 learners

What you'll learn

This course includes

  • 12 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#java #javatutorial #javacourse import java.util.InputMismatchException; import java.util.Scanner; public class Main { public static void main(String[] args) { // Exception = An event that interrupts the normal flow of a program // (Dividing by zero, file not found, mismatch input type) // Surround any dangerous code with a try{} block // try{}, catch{}, finally{} try (Scanner scanner = new Scanner(System.in)) { System.out.print("Enter a number: "); int number = scanner.nextInt(); System.out.println(number); } catch (InputMismatchException e) { System.out.println("That wasn't a number!"); } catch (ArithmeticException e) { System.out.println("YOU CAN'T DIVIDE BY ZERO!"); } catch (Exception e) { // SAFETY NET System.out.println("Something went wrong"); } finally { System.out.println("This always executes"); } } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere