#77 Exception Handling Using try catch in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

For More Queries WhatsApp or Call on : +919008963671

Udemy Courses:

In this lecture we are discussing how to handle exception using try-catch:
-- Exception handling is a mechanism in Java that allows developers to handle
and recover from errors and exceptional conditions that may occur during the execution of a program.
-- One way to handle exceptions in Java is by using the try-catch block.

General Syntax of try -catch to handle exception:
try {
// code that may throw an exception
} catch (ExceptionType1 e1) {
// code to handle the exception of type ExceptionType1
} catch (ExceptionType2 e2) {
// code to handle the exception of type ExceptionType2
} finally {
// optional block of code that is executed regardless of whether an exception was thrown or not
}

we will discussing about everything try, catch ,finally and ExceptionType one by one
-- in this lecture we are only deal with single catch statement with try

// try to handle the exception
class Main{
public static void main(String[] args) {
int i=4; //normal statement
try{
int a = 10/0; //critical statement
/*Not handling excpetion then
if you not handle the exception then it will be thrown to the JVM
and JVM will terminate the program abnormally
and it will not execute the remaining statements
*/

/*
if you handle the exception then it will not be thrown to the JVM
and JVM will not terminate the program abnormally
and it will execute the remaining statements
*/

}catch(Exception e){
}

}

}
-- In the above code, the try block contains the code that may throw an exception.
The catch block catches the exception of a specific type and handles it.

-- statemtns of two types
i)normal statements
Normal Statements:
Normal statements are statements that do not require any special handling, and they are executed in a normal sequence.
e.g Variable declarations and assignments: These statements are used to declare and assign values to variables.

ii)critical statements
Critical statements are statements that can cause an exception or error, and they require special handling.
Handle using :
throw statements: These statements are used to throw an exception.
try-catch statements: These statements are used to handle exceptions.
finally statements: These statements are used to specify a block of code that is always executed, whether an exception is thrown or not.

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

I AM CURRENTLY Watching your java all vedio its really great, super sir, you really super programmer.thank you

mahalakshmi.m
Автор

Namaste sir, Thanks for making this video upto the point. I enjoyed your explanation. <3

whimsicalkins
Автор

Sir what is that x: in print statement

TAKAMAALISMAEELKI
Автор

today I understand the try catch block =D

likevideo
Автор

Sir as you click on Exception term exception inbuilt class is being opened how to get that what are required for that

ggshivaram
Автор

I just checked the comments to see if anyone is joking about the kid that runs 😂😂💀

fedibaklouti
Автор

Picture is not catchby some one is hack always

faijanmirza