What are the different types of Exceptions in Java?

Asked by Last Modified  

10 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Trainer

Main two types 1. Compile time exception ex: FileNotFound Exception,ClassNotFound Exception. 2. Run time exception ex: ArrayIndexOutOfBounds Exception,IllegalTypeException,NullPointer exception,Arithmetic exception. also called Checked exceptions and Unchecked exceptions.
Comments

Tutor

you can say runtime and compile time, checked and uncheked exceptions.
Comments

Teacher

Exceptions are 2 types. 1.Checked 2.Uncheked All the exception for that compiler doesn't care are comes under unchecked exception i.e. ArithmaticException, ArrayIndexOutofBoundexp etc Exceptions which needs to be defined in throws clause of a method r checked exception,ie.sevletException,ClassNotFoundExp,NoSuchFieldException...
read more
Exceptions are 2 types. 1.Checked 2.Uncheked All the exception for that compiler doesn't care are comes under unchecked exception i.e. ArithmaticException, ArrayIndexOutofBoundexp etc Exceptions which needs to be defined in throws clause of a method r checked exception,ie.sevletException,ClassNotFoundExp,NoSuchFieldException etc read less
Comments

Checked Exceptions and Unchecked exceptions
Comments

Software Developer And Trainer

compile time exception and run time exception
Comments

Computer Application

Null pointer exception ArrayOutOfIndex exception DivideByZero exception
Comments

Java,adv java,hibernate,spring

2 types of exceptions exception and error inside exception compile time exception(checked exception) and run time exception(unchecked exception)
Comments

1) Checked Exception The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException, SQLException etc. Checked exceptions are checked at compile-time. 2) Unchecked Exception The classes that extend RuntimeException are known as unchecked exceptions...
read more
1) Checked Exception The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException, SQLException etc. Checked exceptions are checked at compile-time. 2) Unchecked Exception The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked exceptions are not checked at compile-time rather they are checked at runtime. 3) Error Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc. read less
Comments

Java/J2EE Expert & Data Analytic

An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore these exceptions are to be handled. An exception...
read more
An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore these exceptions are to be handled. An exception can occur for many different reasons, below given are some scenarios where exception occurs. A user has entered invalid data. A file that needs to be opened cannot be found. A network connection has been lost in the middle of communications or the JVM has run out of memory. Some of these exceptions are caused by user error, others by programmer error, and others by physical resources that have failed in some manner. Based on these we have three categories of Exceptions you need to understand them to know how exception handling works in Java, Checked exceptions: A checked exception is an exception that occurs at the compile time, 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. For example, if you use FileReader class in your program to read data from a file, if the file specified in its constructor doesn't exist, then an FileNotFoundException occurs, and compiler prompts the programmer to handle the exception. import java.io.File; import java.io.FileReader; public class FilenotFound_Demo { public static void main(String args[]){ File file=new File("E://file.txt"); FileReader fr=new FileReader(file); } } If you try to compile the above program you will get exceptions as shown below. C:\>javac FilenotFound_Demo.java FilenotFound_Demo.java:8: error: unreported exception FileNotFoundException; must be caught or declared to be thrown FileReader fr = new FileReader(file); ^ 1 error Note: Since the methods read() and close() of FileReader class throws IOException, you can observe that compiler notifies to handle IOException, along with FileNotFoundException. Unchecked exceptions: An Unchecked exception is an exception that 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. For example, if you have declared an array of size 5 in your program, and trying to call the 6th element of the array then an ArrayIndexOutOfBoundsExceptionexception occurs. public class Unchecked_Demo { public static void main(String args[]){ int num[]={1,2,3,4}; System.out.println(num[5]); } } If you compile and execute the above program you will get exception as shown below. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at Exceptions.Unchecked_Demo.main(Unchecked_Demo.java:8) Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation. read less
Comments

Exception is an abnormal condition or error that arises during an application processing at run time. The parent class is the Throwable class which has two direct subclasses, java.lang.Error and java.lang.Exception. custom exception that extends the Exception class. The JVM takes care of throwing...
read more
Exception is an abnormal condition or error that arises during an application processing at run time. The parent class is the Throwable class which has two direct subclasses, java.lang.Error and java.lang.Exception. custom exception that extends the Exception class. The JVM takes care of throwing an instance of Error object when there is a system error. The proper Exception handling useful in tracking and debugging errors in the application and sub systems. All the exceptions, which are caught and handled within the calling method or declared in the throws clause of the method, are categorized under checked exceptions. All the checked exceptions must be a sub class of java.lang. Exception class. The JVM will verify that all the checked exceptions are taken care properly by the calling method in the class. Unchecked Exceptions The exception which are raised because of incorrect logic or programming errors are categorized as Unchecked exceptions. These exceptions are sub classes of RunTimeException class. The JVM will not verify for these exceptions in the calling method read less
Comments

View 8 more Answers

Related Questions

How to stop session hijacking programmatically ?
HTTP is a stateless protocol. In order to track users, web applications rely on server side sessions. Two basic ways to link clients(usually browsers) to sessions are through URL rewriting and HTTP cookie....
Mnaohar S
What is the difference between abstraction and encapsulation?
Encapsulation is wrapping, just hiding properties and methods. Encapsulation is used for hide the code and data in a single unit to protect the data from the outside the world. Class is the best example...
Neval
I completed my graduation in 2017, now working as an HR Executive in a Consultancy. I want to move to IT Sector. Which course is best for me to learn and get success in life? Please Suggest me
Dear Kumar, My suggestion is to - become good in one programming language - preferably Java and one O/S preferably Linux. Be aware of Open Source systems. Try to identify the opportunities in your existing...
Kumar
In what ways is C# similar to Java?
C# and Java share several similarities as both are influenced by C and C++: Object-Oriented Programming (OOP): Both languages are designed with a strong emphasis on OOP principles, including encapsulation,...
Aparna
0 0
5
Hi sir, I'm confused between .net and java. What to choose for a career. I have little bit knowledge of asp.net. Please guide me for this. Thank you
Hello Kirit, The application which were devloped about 2 decades back was mostly coded in java and so you will see so many of the application (in several company and outside) written in java. .Net(collectively...
Kirit

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Big Data Hadoop Training
What is Big Data? Big data means really a big data, it is a collection of large datasets that cannot be processed using traditional computing techniques. Big data is not merely a data, rather it has become...

Advance Java
1) Servlet • Basics of Servlet • Servlet Request • Servlet Collaboration • Servlet Config • Servlet Context • Attribute • Session Tracking • Event and Listener •...
A

Most Important Java Interview Topics
Dear All, I am here to help on java interview preparation for fresher and experienced people, please get in touch with me for further details. All interview preparation will be with unique teaching style...

Java Interview Questions & Answers
Java Interview Questions have been designed especially to get you acquainted with the nature of questions you may encounter during your interview for the subject of Java Programming Language. As per my...

Difference Of Inheritance In C++ And Java
In Java , multiple inheritance is not applicable directly but we can implement the concept by using the interfaces. In c++ and Java, the common types of inheritances are: Single Multi level Hybrid Hierarchical

Recommended Articles

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you