- 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 possible to resume java execution after exception occurs?
An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.
There are two types of exceptions in Java.
- Unchecked Exception − An unchecked exception is the one which occurs at the time of execution. These are also called as Runtime Exceptions. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.
- Checked Exception − A checked exception is an exception that occurs at the time of compilation, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation; the programmer should take care of (handle) these exceptions.
Resuming the program
When a checked/compile time exception occurs you can resume the program by handling it using try-catch blocks. Using these you can display your own message or display the exception message after execution of the complete program.
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
Given file path is not found
When a run time exception occurs You can handle runtime exceptions and avoid abnormal termination but, there is no specific fix for runtime exceptions in Java, depending on the exception, type you need to change the code.
Example
public class ExceptionExample { public static void main(String[] args) { //Creating an integer array with size 5 int inpuArray[] = new int[5]; //Populating the array inpuArray[0] = 41; inpuArray[1] = 98; inpuArray[2] = 43; inpuArray[3] = 26; inpuArray[4] = 79; //Accessing index greater than the size of the array System.out.println( inpuArray[3]); } }
Output
26
- Related Articles
- Is it possible to throw exception without using "throws Exception" in java?
- Is it possible to create a custom exception in java without extending Exception class?
- Is it possible to write to MongoDB console in JavaScript execution?
- Is there any way to skip finally block even if some exception occurs in exception block using java?
- Is it possible to rename _id field after MongoDB group aggregation?
- Check if it is possible to sort the array after rotating it in Python
- How to loop the program after an exception is thrown in java?
- Is it possible to instantiate Type-parameter in Java?
- Is it possible to create static constructor in java?
- Is it possible to synchronize the string type in Java?
- What is null pointer exception in Java and how to fix it?
- Is it possible to assign a reference to "this" in java?
- Schedule a task for execution in Java after a given delay
- Is it possible to delete everything after a 'space' in a MySQL field?
- Is it possible to override toString method in an array using Java?

Advertisements