• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Java » Java Exception Handling

Advantages of the Exception-Handling Mechanism

By Dinesh Thakur

The main advantages of the exception-handling mechanism in object oriented programming over the traditional error-handling mechanisms are the following: [Read more…] about Advantages of the Exception-Handling Mechanism

Redirecting and Rethrowing Exceptions in Java

By Dinesh Thakur

Redirecting exceptions using throws

Recall that the code capable of throwing an exception is kept in the try block and the exceptions are caught in the catch block. When there is no appropriate catch block to handle the (checked) exception that was thrown by an object, the compiler does not compile the program. To overcome this, Java allows the programmer to redirect exceptions that have been raised up the call stack, by using the keyword throws. Thus, an exception thrown by a method can be handled either in the method itself or passed to a different method in the call stack. [Read more…] about Redirecting and Rethrowing Exceptions in Java

Exception and Inheritance in Java

By Dinesh Thakur

An exception handler designed to handle a specific type of object may be preempted by another handler whose exception type is a super-class of that exception object. This happens if the exception handler for that exception type appears earlier in the list of exception handlers. That is, while using multiple catch statements, it is important to be aware of the order of exception classes and arrange them correctly. [Read more…] about Exception and Inheritance in Java

Unchecked and Checked Exceptions

By Dinesh Thakur

Based on the severity of the error, Exception classes are categorized into two groups: unchecked exceptions and checked exceptions. Unchecked exceptions are those that can be either handled or ignored. If the programmer ignores an unchecked exception, the program will terminate when such an error occurs. On the other hand, if a handler is provided for an unchecked exception, the result of the occurrence of such an error will depend on the code written in the exception handler. An example of an unchecked exception is the class RuntimeException (and its sub-classes), which is a sub-class of the class Exception. It is a very important class in Java programming. [Read more…] about Unchecked and Checked Exceptions

Constructors and Methods in Throwable Class

By Dinesh Thakur

Constructors

There are four constructors in the Throwable class:

• Throwable ()

• Throwable (String message) [Read more…] about Constructors and Methods in Throwable Class

Exception Hierarchy in Java

By Dinesh Thakur

When a condition causes an exception to be thrown, that exception is thrown either by the Java virtual machine or by the Java throw statement. Exceptions are represented by objects instantiated from the class java.lang. Throwable or one of its sub-classes. Java also allows users to define classes that can throw their own (user-defined) exception objects as needed in their design; however, this new class must extend the throwable class or one of its sub-classes. [Read more…] about Exception Hierarchy in Java

Creating Own Exception in Java Example

By Dinesh Thakur

Java.lang.Exception Class is the superclass for all exceptions in Java. To creating our own extensions, we simply extend this class. [Read more…] about Creating Own Exception in Java Example

ArrayStoreException in Java Example

By Dinesh Thakur

ArrayStoreException is thrown when ever we storing something in an array. If we store wrong type object into an array then this will be thrown. Here is the Java example which explains this. [Read more…] about ArrayStoreException in Java Example

Chained Exceptions in Java Example

By Dinesh Thakur

Sometimes a catch block catches one exception type and then throws a new exception with additional information. This is known as chained exception. This feature allows you to associate another exception with an exception. The second exception describes the cause of the firstexception. [Read more…] about Chained Exceptions in Java Example

Defining Your Own Exception Class Java Example

By Dinesh Thakur

So far you have been using the pre-defined exception classes provided by the Java API. However, if you encounter a problem that cannot be adequately described by the predefined exception classes, you can create your own exception class. [Read more…] about Defining Your Own Exception Class Java Example

Nested Try Statements in Java Examples

By Dinesh Thakur

So far we have been using just single try statement. However, it is possible to nest a try statement inside another try statement. If one try block does not have a corresponding catch block that handles the exception, Java will search the next outer try block for a catch block that will handle the exception, back through successive nesting. If the Java cannot find the catch block for the exception, it will pass the exception to its default exception handler. [Read more…] about Nested Try Statements in Java Examples

Finally Block in Java with Example

By Dinesh Thakur

If an exception occurs inside a try block and there is no matching catch block, the method terminates without further executing any lines of code from that method. For example, suppose you may want to close a file that has been opened even if your program could not read from the file for some reason. In other words, you want to close the file irrespective whether the read is successful or not. If you want that some lines of code must be executed regardless of whether or not there is matching catch block, put those lines inside the finally block. [Read more…] about Finally Block in Java with Example

Throws Clause in Java Example

By Dinesh Thakur

The basic principle of Java error handling mechanism is that an exception must either be handled by the method in which it is raised or passed along the call chain for another method to handle it. Suppose a method throws an exception, that is neither a subclass of RuntimeException nor of Error i.e. if it throws a checked exception, then Java requires that the method either handles it or declares it. If the method does not handle the checked exception then the method must declare it using the throws keyword. [Read more…] about Throws Clause in Java Example

Rethrowing Exceptions Java Example

By Dinesh Thakur

There might be situations in your program where you want to both catch an exception in your code and also want its caller be notified about the exception. This is possible by rethrowing the exception using throw statement. [Read more…] about Rethrowing Exceptions Java Example

Throw Clause Example in Java

By Dinesh Thakur

You can also throw an exception explicitly. This is accomplished using the throw statement. A throw statement is executed to indicate that an exception has occurred. The exception that you throw using the throw statement can either be the standard system exception or the one that are created by you. The syntax of throw statement is as follows, [Read more…] about Throw Clause Example in Java

Throwable Class Example in Java

By Dinesh Thakur

The Throwable class provides the following commonly used methods.

• String getMessage (): It returns the description of the exception. It includes fully qualified name of the Exception class and a brief description of the exception. [Read more…] about Throwable Class Example in Java

Stack Trace in Java Example

By Dinesh Thakur

When an exception is thrown in your program, you can find the exact statement in your program that caused the exception to occur by examining the lines that are displayed right after the line that indicates which exception was encountered. These lines of information that are displayed when an exception occurs is known as Stack trace. It lists the different methods that the exception passed through before your program was completely aborted. Each line in the stack trace contains not only the method name and the corresponding classname but also the name of the source file that contains the class and the line number where the exception occurred. [Read more…] about Stack Trace in Java Example

Multiple Catch Blocks in Java Example

By Dinesh Thakur

Typically, code in a try-block can throw more than one kind of exception. If this is the case then you can put several catch blocks after the try block to handle them, one for each possible exception. When an exception is generated, the JVM searches the catch blocks in order. The first catch block with a parameter that matches the exception thrown will execute, any remaining catch blocks will be skipped. [Read more…] about Multiple Catch Blocks in Java Example

DivideByZeroException Java Example

By Dinesh Thakur

Exception handling is a technique of processing problems that occur during the execution of the program. Using exception handling, we can test the code and avoid it from exiting abruptly. [Read more…] about DivideByZeroException Java Example

What are the causes of exceptions in java

By Dinesh Thakur

A java exception can be thrown only in the following three scenarios: [Read more…] about What are the causes of exceptions in java

What is an Applet?

By Dinesh Thakur

We Know that java provides us the facility for both creating CUI and GUI Programs All the Previous Topics are Related with the CUI But Applets Provides the ability to user for creating Graphical Programs Like Creating Buttons, Creating Events such that Executing the Code when a user Clicks on Button Etc. There are two type of Applets Like Stand Alone or either Local Applets. [Read more…] about What is an Applet?

Exception Handling in Java with Examples

By Dinesh Thakur

Exception handling in Java is a technique of processing problems that occur during the execution of the program. Using exception handling, we can test the code and avoid it from exiting abruptly.

Exception handling in Java is accomplished using five keywords: try, catch, throw, throws and finally.

To understand what exceptions are and how to handle them, let us consider a program that displays two integers’ quotient. [Read more…] about Exception Handling in Java with Examples

Exceptions – What is Exceptions? Type of Exceptions

By Dinesh Thakur

Exceptions:- Exception is a condition Which is Responsible for Occurrence of Error Like Divide by Zero is an condition that never be possible So we can call it an Exception which halts or stops the Execution of Program In java there is an Exception Class Which is Responsible for producing an Error Message when an Error has occurred.  [Read more…] about Exceptions – What is Exceptions? Type of Exceptions

Error – What is Error? Type of Error.

By Dinesh Thakur

Many Times a  Program has to face some errors An Error is an Situation when a Compiler either doesn’t Execute  statements or either Compiler will Produce Wrong Result .Various types of Errors are there like :- [Read more…] about Error – What is Error? Type of Error.

Differences Between Applications and Applets

By Dinesh Thakur

Java is a general-purpose, object-oriented programming language. We can develop two types of Java programs : [Read more…] about Differences Between Applications and Applets

Primary Sidebar

Java Tutorials

Java Tutorials

  • Java - Home
  • Java - IDE
  • Java - Features
  • Java - History
  • Java - this Keyword
  • Java - Tokens
  • Java - Jump Statements
  • Java - Control Statements
  • Java - Literals
  • Java - Data Types
  • Java - Type Casting
  • Java - Constant
  • Java - Differences
  • Java - Keyword
  • Java - Static Keyword
  • Java - Variable Scope
  • Java - Identifiers
  • Java - Nested For Loop
  • Java - Vector
  • Java - Type Conversion Vs Casting
  • Java - Access Protection
  • Java - Implicit Type Conversion
  • Java - Type Casting
  • Java - Call by Value Vs Reference
  • Java - Collections
  • Java - Garbage Collection
  • Java - Scanner Class
  • Java - this Keyword
  • Java - Final Keyword
  • Java - Access Modifiers
  • Java - Design Patterns in Java

OOPS Concepts

  • Java - OOPS Concepts
  • Java - Characteristics of OOP
  • Java - OOPS Benefits
  • Java - Procedural Vs OOP's
  • Java - Polymorphism
  • Java - Encapsulation
  • Java - Multithreading
  • Java - Serialization

Java Operator & Types

  • Java - Operator
  • Java - Logical Operators
  • Java - Conditional Operator
  • Java - Assignment Operator
  • Java - Shift Operators
  • Java - Bitwise Complement Operator

Java Constructor & Types

  • Java - Constructor
  • Java - Copy Constructor
  • Java - String Constructors
  • Java - Parameterized Constructor

Java Array

  • Java - Array
  • Java - Accessing Array Elements
  • Java - ArrayList
  • Java - Passing Arrays to Methods
  • Java - Wrapper Class
  • Java - Singleton Class
  • Java - Access Specifiers
  • Java - Substring

Java Inheritance & Interfaces

  • Java - Inheritance
  • Java - Multilevel Inheritance
  • Java - Single Inheritance
  • Java - Abstract Class
  • Java - Abstraction
  • Java - Interfaces
  • Java - Extending Interfaces
  • Java - Method Overriding
  • Java - Method Overloading
  • Java - Super Keyword
  • Java - Multiple Inheritance

Exception Handling Tutorials

  • Java - Exception Handling
  • Java - Exception-Handling Advantages
  • Java - Final, Finally and Finalize

Data Structures

  • Java - Data Structures
  • Java - Bubble Sort

Advance Java

  • Java - Applet Life Cycle
  • Java - Applet Explaination
  • Java - Thread Model
  • Java - RMI Architecture
  • Java - Applet
  • Java - Swing Features
  • Java - Choice and list Control
  • Java - JFrame with Multiple JPanels
  • Java - Java Adapter Classes
  • Java - AWT Vs Swing
  • Java - Checkbox
  • Java - Byte Stream Classes
  • Java - Character Stream Classes
  • Java - Change Color of Applet
  • Java - Passing Parameters
  • Java - Html Applet Tag
  • Java - JComboBox
  • Java - CardLayout
  • Java - Keyboard Events
  • Java - Applet Run From CLI
  • Java - Applet Update Method
  • Java - Applet Display Methods
  • Java - Event Handling
  • Java - Scrollbar
  • Java - JFrame ContentPane Layout
  • Java - Class Rectangle
  • Java - Event Handling Model

Java programs

  • Java - Armstrong Number
  • Java - Program Structure
  • Java - Java Programs Types
  • Java - Font Class
  • Java - repaint()
  • Java - Thread Priority
  • Java - 1D Array
  • Java - 3x3 Matrix
  • Java - drawline()
  • Java - Prime Number Program
  • Java - Copy Data
  • Java - Calculate Area of Rectangle
  • Java - Strong Number Program
  • Java - Swap Elements of an Array
  • Java - Parameterized Constructor
  • Java - ActionListener
  • Java - Print Number
  • Java - Find Average Program
  • Java - Simple and Compound Interest
  • Java - Area of Rectangle
  • Java - Default Constructor Program
  • Java - Single Inheritance Program
  • Java - Array of Objects
  • Java - Passing 2D Array
  • Java - Compute the Bill
  • Java - BufferedReader Example
  • Java - Sum of First N Number
  • Java - Check Number
  • Java - Sum of Two 3x3 Matrices
  • Java - Calculate Circumference
  • Java - Perfect Number Program
  • Java - Factorial Program
  • Java - Reverse a String

Other Links

  • Java - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2023. All Rights Reserved.