---
title: "If I write System.exit(0); at the end of the try block, will the finally block still execute?"  
description: "If I write System.exit(0); at the end of the try block, will the finally block still execute?"  
author: "Sumit Kesarwani"  
published: 2014-08-26  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/2015/if-i-write-system-exit-0-at-the-end-of-the-try-block-will-the-finally-block-still-execute  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# If I write System.exit(0); at the end of the try block, will the finally block still execute?

No. In this case the finally block will not execute because when you say System.exit(0); the control immediately goes out of the program, and thus finally never executes.

## Answers

### Answer by Sumit Kesarwani

No. In this case the finally block will not execute because when you say System.exit(0); the control immediately goes out of the program, and thus finally never executes.


---

Original Source: https://www.mindstick.com/interview/2015/if-i-write-system-exit-0-at-the-end-of-the-try-block-will-the-finally-block-still-execute

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
