- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the finally block in Java?
The finally block follows a try block or a catch block. A finally block of code forever executes, no matter prevalence of an Exception.
Example
public class ExcepTest { public static void main(String args[]) { int a[] = new int[2]; try { System.out.println("Access element three :" + a[3]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Exception thrown :" + e); } finally { a[0] = 6; System.out.println("First element value: " + a[0]); System.out.println("The finally statement is executed"); } } }
Output
Exception thrown : java.lang.ArrayIndexOutOfBoundsException: 3 First element value: 6 The finally statement is executed
- Related Articles
- Is finally block always get executed in Java?
- Does code form Java finally block
- Can finally block be used without catch in Java?
- Is there a case when finally block does not execute in Java?
- Java Program to Use finally block for Catching Exceptions
- Is there any way to skip finally block even if some exception occurs in exception block using java?
- Explain Try/Catch/Finally block in PowerShell
- What is the try block in Java?
- What is the catch block in Java?
- Will a finally block execute after a return statement in a method in Java?
- What is the difference between final, finally and finalize() in Java?
- What are try, catch, finally blocks in Java?
- what is the significance of finally in javascript?
- What is finally statement in C#?
- What are block lambda expressions in Java?

Advertisements