java tutorial 34 Custom exception class || throw keyword in java

Publicado el: 15 julio 2021
en el canal de: Internpe
24
3

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 :)


En esta página del sitio puede ver el video en línea java tutorial 34 Custom exception class || throw keyword in java de Duración hora minuto segunda en buena calidad , que subió el usuario Internpe 15 julio 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 24 veces y le gustó 3 a los espectadores. Disfruta viendo!