#77 Exception Handling Using try catch in Java

  Рет қаралды 104,118

Telusko

Telusko

Күн бұрын

Check out our courses:
Enterprise Java Spring Microservices: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : go.telusko.com...
Coupon: TELUSKO20 (20% Discount)
For More Queries WhatsApp or Call on : +919008963671
Udemy Courses:
Spring: go.telusko.com...
Java:- go.telusko.com...
Java Spring:- go.telusko.com...
Java For Programmers:- go.telusko.com...
Python : go.telusko.com...
Git : go.telusko.com...
Docker : go.telusko.com...
website : courses.telusk...
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){
System.out.println("Some exception occured");
}
System.out.println("We are coming out of the try catch block successfully");
}
}
-- 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.
Github repo : github.com/nav...
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com

Пікірлер: 20
@mahalakshmi.m4549
@mahalakshmi.m4549 Жыл бұрын
I AM CURRENTLY Watching your java all vedio its really great ,super sir ,you really super programmer.thank you
@allblue944
@allblue944 28 күн бұрын
Do you know what else super is? Yes it's a keyword
@backmambaxd3397
@backmambaxd3397 Жыл бұрын
what an explanation just WOW!!!
@whimsicalkins5585
@whimsicalkins5585 Жыл бұрын
Namaste sir, Thanks for making this video upto the point. I enjoyed your explanation.
@waroon.waroon2555
@waroon.waroon2555 11 ай бұрын
clear and perfect🎉
@patrik1389
@patrik1389 7 ай бұрын
thx
@faijanmirza4561
@faijanmirza4561 9 ай бұрын
Let's try now
@T_M_T_K
@T_M_T_K 5 ай бұрын
thank you so much
@OmkarSolanke-q2f
@OmkarSolanke-q2f 5 ай бұрын
thank you 😍
@g16gshivaram75
@g16gshivaram75 Жыл бұрын
Sir as you click on Exception term exception inbuilt class is being opened how to get that what are required for that
@sanjaysrivatsa4162
@sanjaysrivatsa4162 Жыл бұрын
Use control key and click
@likevideo00
@likevideo00 5 ай бұрын
today I understand the try catch block =D
@TAKAMAALISMAEELKI
@TAKAMAALISMAEELKI 4 ай бұрын
Sir what is that x: in print statement
@_A_B_C_D_E_F
@_A_B_C_D_E_F 4 ай бұрын
Just ignore, and pretend as if it doesn’t exist. VS Code automatically just puts it to show the argument that is expected in that particular method.
@udayharishgowda1522
@udayharishgowda1522 Жыл бұрын
thanks
@unknownplanet699
@unknownplanet699 10 ай бұрын
who throw exception and object??
@faijanmirza4561
@faijanmirza4561 9 ай бұрын
By google catch
@fedibaklouti3239
@fedibaklouti3239 4 ай бұрын
I just checked the comments to see if anyone is joking about the kid that runs 😂😂💀
@faijanmirza4561
@faijanmirza4561 9 ай бұрын
Picture is not catchby some one is hack always
@faijanmirza4561
@faijanmirza4561 9 ай бұрын
Email is out faijan sign is mobile
#78 Try with Multiple Catch in Java
10:20
Telusko
Рет қаралды 77 М.
#76  What is Exception in Java
5:19
Telusko
Рет қаралды 85 М.
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 33 МЛН
Ozoda - Lada ( Official Music Video 2024 )
06:07
Ozoda
Рет қаралды 32 МЛН
Миллионер | 1 - серия
34:31
Million Show
Рет қаралды 2,9 МЛН
Exception Handling in Java Tutorial
13:20
Coding with John
Рет қаралды 397 М.
JWT авторизация. Основы JWT - механизма.
6:45
Хочу вАйти
Рет қаралды 12 М.
#40 Encapsulation in Java
11:42
Telusko
Рет қаралды 187 М.
#80 Exception throw keyword in Java
5:35
Telusko
Рет қаралды 113 М.
Advanced Exception Handling in Python
12:06
NeuralNine
Рет қаралды 64 М.
#26 Stack And Heap in Java
12:37
Telusko
Рет қаралды 264 М.
Java exception handling ⚠️
7:53
Bro Code
Рет қаралды 112 М.
#82 Ducking Exception using throws in Java
9:55
Telusko
Рет қаралды 74 М.
Checked vs. Unchecked Exceptions in Java Tutorial - What's The Difference?
10:14
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 33 МЛН