Handling Specific Exceptions in Java
#############################
Video Source: www.youtube.com/watch?v=osEjmECD8bI
Check out our courses: • Enterprise Java Spring Microservices: https://go.telusko.com/enterpriseJava • Coupon: TELUSKO10 (10% Discount) • Master Java Spring Development : https://go.telusko.com/masterjava • Coupon: TELUSKO20 (20% Discount) • For More Queries WhatsApp or Call on : +919008963671 • Udemy Courses: • Spring: https://go.telusko.com/udemyteluskosp... • Java:- https://go.telusko.com/udemyteluskojava • Java Spring:- https://go.telusko.com/Udemyjavaspring • Java For Programmers:- https://go.telusko.com/javaProgrammers • Python : https://go.telusko.com/udemyteluskopy... • Git : https://go.telusko.com/udemyteluskogit • Docker : https://go.telusko.com/udemyteluskodo... • website : https://courses.telusko.com/ • • 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 : https://github.com/navinreddy20/Javac... • Java:- https://bit.ly/JavaUdemyTelusko • Spring:- https://bit.ly/SpringUdemyTelusko • More Learning : • Java :- https://bit.ly/3x6rr0N • Python :- https://bit.ly/3GRc7JX • Django :- https://bit.ly/3MmoJK6 • JavaScript :- https://bit.ly/3tiAlHo • Node JS :- https://bit.ly/3GT4liq • Rest Api :-https://bit.ly/3MjhZwt • Servlet :- https://bit.ly/3Q7eA7k • Spring Framework :- https://bit.ly/3xi7buh • Design Patterns in Java :- https://bit.ly/3MocXiq • Docker :- https://bit.ly/3xjWzLA • Blockchain Tutorial :- https://bit.ly/3NSbOkc • Corda Tutorial:- https://bit.ly/3thbUKa • Hyperledger Fabric :- https://bit.ly/38RZCRB • NoSQL Tutorial :- https://bit.ly/3aJpRuc • Mysql Tutorial :- https://bit.ly/3thpr4L • Data Structures using Java :- https://bit.ly/3MuJa7S • Git Tutorial :- https://bit.ly/3NXyCPu • Donation: • PayPal Id : navinreddy20 • https://www.telusko.com
#############################
New on site