- 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
Is it necessary that a try block should be followed by a catch block in Java?
Not necessarily catch, a try must be followed by either catch or finally block.
Example
import java.io.File; public class Test{ public static void main(String args[]){ System.out.println("Hello"); try{ File file = new File("data"); } } }
Output
C:\Sample>Javac Test.java Test.java:5: error: 'try' without 'catch', 'finally' or resource declarations try{ ^ 1 error
- Related Articles
- Can we declare a try catch block within another try catch block in Java?
- Can we have a try block without a catch block in Java?\n
- Can a try block have multiple catch blocks in Java?
- Explain Try/Catch/Finally block in PowerShell
- Can we define a try block with multiple catch blocks in Java?
- Is it possible to have multiple try blocks with only one catch block in java?
- Is it possible to catch multiple Java exceptions in single catch block?
- What is the try block in Java?
- What is the catch block in Java?
- Can finally block be used without catch in Java?
- Can we to override a catch block in java?
- Why we can't initialize static final variable in try/catch block in java?
- Can we write code in try/catch block in JSP as well?
- How to raise an exception in one except block and catch it in a later except block in Python?
- Can we have an empty catch block in Java?

Advertisements