123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computers >> View Article

Exception Handling Why We Use In Java

Profile Picture
By Author: Infocampus
Total Articles: 33
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

When java executing any faulty statement , an interruption occur or program terminated improperly .that is known as exception.
Faulty statement is the statement which are having any logical error.

Exception Handling: To avoid any program to terminate improperly we use exception handling mechanism.When any exception occur main method will through it to JVM(Java Virtual Machine ).
JVM handle the exception using exception handling mechanism.

Ways to handle the exception :
In java there is two ways to handle the exception-
[1] try -catch
[2] throws
java course in bangalore
Using try-catch: For handling the exception write the faulty statement inside the try block and with the mechanism inside the catch block. When Exception occur an object will be created ,this object will be throw by the try block and catch by the catch block.
If try block is there then catch block should be there. We can use the multiple try block and single catch block.

Using throws: throws is used to throw the exception. When exception occur in any method , it will through to the main method ...
... and main method through the exception to the JVM . JVM will handle the exception.

Types of Exception :
(i)Compile time exception
(ii)Run time exception
java training center bangalore

Compile time exception /Checked Exception: When the exception is occured at compile time is known as compile time exception .Also called as checked exception.These exceptions cannot simply be ignored at the time of compilation, the programmer should handle these exceptions.
Example : File not found exception, IO exception

Run Time exception : When exception is occured at run time is known as run time exception.These are also called as unchecked exception. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.

Example : ArrayIndexOutofBound Exception , Arithmetic exception.
Best core java training in bangalore

Hierarchy of the Exception:

All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class there is another subclass called Error which is derived from the Throwable class.
Errors are abnormal conditions that happen in case of severe failures, these are not handled by the Java programs. Errors are generated to indicate errors generated by the runtime environment.
Example: JVM is out of memory. Normally, programs cannot recover from errors.
The Exception class has two main subclasses: Checked Exception class and RuntimeException Class.
Difference between Error and Exception :

Advance java training in Bangalore
java.lang.Error and java.lang.Exception classes are sub classes of java.lang.Throwable class

[1] Errors occur because of the environment where application is running.example :
OutOfMemoryError and StackOverflowError.
Exception occur because of application Which are mainly caused by the application itself.

[2] Recovering from Error is not possible. The only solution to errors is to terminate the execution. Where as we can recover from Exception by using either try-catch blocks or throwing exception back to caller.

[3] Exceptions in java are divided into two categories – checked and unchecked. Where as all Errors belongs to only one category i.e unchecked.

[4] Errors in java are of type java.lang.Error.Exceptions in java are of type java.lang.Exception.

Java/j2ee classes bangalore
[5]Errors happen at run time. They will not be known to compiler.Checked exceptions are known to compiler where as unchecked exceptions are not known to compiler because they occur at run time.

This is the short description about the Exception. To know more about the java for getting the job easily get classes in Infocampus Software Training Institute.

Author :
Infocampus provides java course in bangalore with the live project. It provides training on Core & Advance Java with the 100% job support project.

Mock tests And Mock Interviews are conducted for the java/j2ee classes. 4 days Free Demo classes are available before joining the Java Course in Infocampus. Complete practical session are available for Advance java training .
Learn oops concept , thread ,packages,servlet, spring,thread in the best core java training institute in the easiest way to get the job easily.
Call at : 9738001024 and to get more details on Java training center Visit : http://www.infocampus.co.in/java-training-bangalore.html

Total Views: 561Word Count: 664See All articles From Author

Add Comment

Computers Articles

1. Exploring How Ai In The Cloud Can Transform Your Business
Author: TechDogs

2. The Power Of Cloud And Ai: A New Era Of Collaboration
Author: TechDogs

3. Get Business Insights Using Expedia & Booking. Com Review Data Scraping
Author: DataZivot

4. Top 10 Reasons A Strong Communication Strategy Drives Prm Program Success
Author: Archi

5. Achieve Scalable Web Scraping With Aws Lambda
Author: Devil Brown

6. Overcoming Common Challenges In Iso 27001 Implementation
Author: Jenna Miller

7. Basic Computer Course: Your Gateway To Skill Development | The Institute Of Professional Accountants
Author: Tipa Institute

8. Top 7 Advantages Of React Js
Author: Bella Stone

9. Top 7 App Marketing Tools For Mobile Success
Author: Bella Stone

10. Revolutionizing Education Management With Samphire It Solution Pvt Ltd’s Erp Software
Author: CONTENT EDITOR FOR SAMPHIRE IT SOLUTIONS PVT LTD

11. Top 10 Healthcare Technology Trends
Author: goodcoders

12. "building Tomorrow’s Factories: The Role Of Automation & Robotics In Modern Manufacturing"
Author: andrew smith

13. The Ultimate Guide To The Best Ecommerce Plugin For Wordpress
Author: Rocket Press

14. Xsosys Erp: A Scalable Solution For Businesses In Any Industry
Author: Xsosys Technology(S) Pte. Ltd.

15. Rental Management Software: A Complete Solution For Car, Property, And Coworking Space
Author: RentAAA

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: