Learn Throw keyword in Java | EasyTechCode

preview_player
Показать описание
#throwkeyword #javatutorial #java #javaprogramming #javabasic #javaforbeginners
In this video we learn about throw keyword.

Throw Keyword
_______________
User can throw exception directly.
It used to throw an exception explicitly.
We can throw either checked or unchecked exception.
We may set certain condition to throw an exception explicitly.
Syntax
new throw AnyException(“Name”);

For example:
new throw ArithmeticException(“Divide by Zero”)
We can throw only instance of Throwable or Sub
Classses of Throwable class

Example program
_________________
class sample_throw
{
public static void main(String a[])
{
int e;
if(e==0)
{

throw new ArithmeticException("Exception Thrown by Easy CodeTech");

}
}
}
To run type
java sample_throw 0
The value zero is assigned throws command line argument.
The zero is assigned as
a[0]=0;
output
_______

Other Video Link
________________
How to compile and run java program in notepad
Program to print welcome to java:
Overloading Methods:
Рекомендации по теме