In this java tutorial we learn how to make a custom exception class and learn about throw keyword...
Exception handling part 1 :-
• java tutorial 33 Exception handing in java
Welcome to code terminators : )
👉👉👉👉👉👉👉👉
playlist ( java tutorial ):-
• Java(Beginner) Programming
The throw keyword in Java is used to explicitly throw an exception from a method or any block of code. We can throw either checked or unchecked exception. The throw keyword is mainly used to throw custom exceptions.
Syntax:
throw Instance
Example:
throw new ArithmeticException("/ by zero");
But this exception i.e, Instance must be of type Throwable or a subclass of Throwable. For example Exception is a sub-class of Throwable and user defined exceptions typically extend Exception class. Unlike C++, data types such as int, char, floats or non-throwable classes cannot be used as exceptions.
The flow of execution of the program stops immediately after the throw statement is executed and the nearest enclosing try block is checked to see if it has a catch statement that matches the type of exception. If it finds a match, controlled is transferred to that statement otherwise next enclosing try block is checked and so on. If no matching catch is found then the default exception handler will halt the program.
Thanks for watching :)
In questa pagina del sito puoi guardare il video online java tutorial 34 Custom exception class || throw keyword in java della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Internpe 15 luglio 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 24 volte e gli è piaciuto 3 spettatori. Buona visione!