Войти
  • 17127Просмотров
  • 1 год назадОпубликованоBro Code

Learn EXCEPTION HANDLING in 8 minutes! ⚠️

#java #javatutorial #javacourse import ; import ; 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( )) { ("Enter a number: "); int number = (); (number); } catch (InputMismatchException e) { ("That wasn't a number!"); } catch (ArithmeticException e) { ("YOU CAN'T DIVIDE BY ZERO!"); } catch (Exception e) { // SAFETY NET ("Something went wrong"); } finally { ("This always executes"); } } }