Watch and track your favorite playlist.
Curated by: Telusko (106 videos)
Check out our courses: Mastering Agentic AI with Java : https://go.telusko.com/agentic-ai Coupon: TELUSKO10 (10% Discount) DevOps Bootcamp: https://go.telusko.com/complete-devops Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/learn-master Coupon: TELUSKO10 (10% Discount) For More Queries WhatsApp or Call on : +919008963671 website : https://telusko.com/ Udemy Courses: Java Spring:- https://go.telusko.com/Udemyjavaspring Java:- https://go.telusko.com/udemyteluskojava Spring: https://go.telusko.com/udemyteluskospring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker Instagram : https://www.instagram.com/navinreddyofficial/ Linkedin : https://in.linkedin.com/in/navinreddy20 WhatsApp : https://go.telusko.com/whatsapp TELUSKO Android App : https://go.telusko.com/TELUSKOAPP TELUSKO IOS App : https://apple.co/3SsgmU2 Discord : https://discord.gg/D8hWe9BqfF In this lecture we are discussing about custom Exception: --Java provides a set of built-in exceptions that cover most of the common error scenarios in a program. --there may be cases where we need to define our own exception class to represent an error specific to your program. #1 How to create custom exception in java? class MyException extends Exception{ // this class is own exception class defined by according to our need } -- MyException is a custom exception class that extends the Exception class. #2 Now we want to pass some message -- we need a constructor that takes a String message, which is passed to the parent constructor using the super keyword. e.g - public class MyException extends Exception { public MyException(String message) { super(message); } } Note: we can add additional properties and methods to your custom exception class as needed, just like you would with any other Java class. #3 As per need we can throw custom Exception e.g public class Main{ public static void main(String []args){ try{ throw new NavinException("This is my exception"); }catch(NavinException e){ System.out.println(e.getMessage()); } } } class NavinException extends Exception{ public NavinException(String s) { super(s); } } Important Notes: -- we can create a custom exception by extending the Throwable class in Java -- we can create a custom exception by extending the Exception class in Java -- we can create a custom exception by extending the Exception class or one of its subclasses, such as RuntimeException. Recommended: -- Generally recommended to create custom exceptions by extending the Exception class or one of its subclasses, such as RuntimeException. This makes it easier to handle your exception in a specific way and ensures that it behaves like other exceptions in the Java platform. -- it is not recommended create custom exception using Throwable, the Throwable class is typically used to create other types of exceptions, such as errors and checked exceptions, rather than custom exceptions. Github repo : https://github.com/navinreddy20/Javacode.git 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