- 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 catch block in Java?
A catch statement involves declaring the type of exception you are trying to catch. If an exception occurs in the try block, the catch block (or blocks) that follows the try is checked. If the type of exception that occurred is listed in a catch block, the exception is passed to the catch block much as an argument is passed into a method parameter.
Example
import java.io.File; import java.io.FileInputStream; public class Test { public static void main(String args[]) { System.out.println("Hello"); try { File file = new File("my_file"); FileInputStream fis = new FileInputStream(file); } catch(Exception e) { System.out.println("Given file path is not found"); } } }
Output
Hello Given file path is not found
- Related Articles
- Is it possible to catch multiple Java exceptions in single catch block?
- Can we declare a try catch block within another try catch block in Java?
- What is the difference between throw e and throw new Exception(e) in catch block in java?
- Can we to override a catch block in java?
- Can we have an empty catch block in Java?
- Can finally block be used without catch in Java?
- Is it necessary that a try block should be followed by a 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?
- What is the try block in Java?
- What is the finally block in Java?
- Catch block and type conversion in C++
- 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?

Advertisements