Java Exception handling tutorial

Exception: The exception refers to an exceptional event. Exception is an event that disrupts the normal flow of the program, during program execution. Exception object: When an error occurs within a method, the method creates an object and hands it to the runtime system. This object is known as an exception object. It contains the … Read more

Privacy Policy

Privacy Policy for www.w3schools.blog If you require any more information or have any questions about our privacy policy, please feel free to contact us by email at [email protected]. At www.w3schools.com, the privacy of our visitors is of extreme importance to us. This privacy policy document outlines the types of personal information is received and collected by www.w3schools.com … Read more

Java Marker interface

Marker/Tagging Interfaces: An interface with no methods is known as a marker or tagged interface.   Why marker interface used: It provides some useful information to the JVM/compiler so that the JVM/compiler performs some special operations on it. It is used for better readability of code.  Example: Serializable, Cloneable, etc.   Syntax public interface Interface_Name … Read more

Java Throwable class methods

1. getMessage(): returns the message string about the exception. Syntax: public String getMessage()    2. getCause(): returns the cause of the exception. It will return null if the cause is unknown or non-existent. Syntax: public Throwable getCause()    3. toString(): returns a short description of the exception. Description of the exception = class name + “: “ + message. … Read more

Java Custom exception

Custom exception:   You can define your own exception also. These exceptions are known as custom exceptions. Note: 1. For writing custom-checked exceptions, extend the Exception class. 2. For writing custom unchecked exceptions, extend the RuntimeException class. Java Custom Exception Example   class MyException extends Exception { public MyException(String message) { super(message); } } class … Read more

Java Exception handling with method overriding

If the superclass method does not declare an exception then the subclass overridden method cannot declare the checked exception but it can declare an unchecked exception. If the superclass method declares an exception then the subclass overridden method can declare the same exception, subclass exception, or no exception but cannot declare the parent exception of … Read more

Java Exception propagation

Exception propagation is a way of propagating exceptions from method to method. Let an exception occur in a method at the top of the call stack and if it is not caught then it propagates to the previous method in the call stack, if it is not caught here then it again propagates to the … Read more

Java throw keyword

throw is used to throw an exception object explicitly. It can take only one argument and that will be an exception object. Exception object to be thrown can be of either checked or unchecked exception type.   Syntax throw exception_object;   Java throw keyword Example class ArithmaticTest{ public void division(int num1, int num2){ try{ //java.lang.ArithmeticException … Read more