Skip to main content

Posts

User Defined Exception Handling

Introduction: To develop the project, we must create our own Exception class, as Sun microsystem has not given any exception class some requirements which are not in common. So, what is User defined exception is? Exception class defined by Developer is called as User Defined Exception or Custom exception Steps to create User Defined Exception: Write a class that extends java.lang.Exception. In User defined class, define minimum 2 constructors. No-argument constructor String parameter with logic “super(message)” to create exception object with message.  No need to define any method, why because exception class is not meant for developing business logic , instead it is used for terminating method logic execution by throwing it’s object. ------------------------------------------------------------------------------------------------------------ package com.app.exceptions; /**  *  * @author Shashank Mungantiwar  * ...

Exception Propagation and throw-throws keyword

Exception Propagation: Sending exception from one method to another method is called exception propagation Here propagation is nothing but sending. So guys what is the situation when we are going to implement this propagation concept? Answer to this question is when we throw an exception, if it is not caught in that method it is propagated to another method and interesting thing is that we don’t need to do anything in this process we just need to throw an exception that’s it. Rule: If the propagated exception is checked exception then not only current method developer but also method’s caller method developer should caught or report that checked exception else it leads to same compiler exception….CE: Unreported Exception So according to that basic rule is “If checked exception is raised the method either directly by using throw keyword or indirectly by a method call it must be caught or reported. void m1() throws ClassNotFoundException{ ...