ALL >> Computer-Programming >> View Article
Exception Handling A Concept To Avoid The Program Terminate Improperly In Java
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
advanced java training 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. java /j2ee classes bangalore
Types of Exception :
(i)Compile time exception
(ii)Run time exception
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.
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.java training center bangalore 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 :
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.java course in bangalore
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.
[5]Errors happen at run time. Best core java training in bangalore 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 Handling to know more about the java join Infocampus Software Training Institute.
Author : Infocampus provides Advanced Java Training in Bangalore with the 100% career assistance and real time project.It provides Core and Advanced Java Training in lesser fees.Learn packages,thread ,singleton class,spring & hibernate ...in java training center bangalore.
Attend 4 days free demo classes on java/j2ee classes bangalore . Java course is provided by the 10+ years experienced trainers.Fully practical session is available for best core java training.
To get the 100% job support and for demo classes call at : 9738001024 or to know the java syllabus enquire at : http://www.infocampus.co.in/java-training-bangalore.html
Add Comment
Computer Programming Articles
1. Which Institute Is Best For Coding And Programming In Bhopal?Author: Shankar Singh
2. Top 9 Benefits Of Custom Mobile Application Development
Author: Byteahead
3. Top 10 Creative Business Ideas For Entrepreneurs
Author: Byteahead
4. Top 10 Apps Like Tiktok Everyone Should Check Out
Author: Byteahead
5. Is The Apple Watch Series 7 Worth It For Seniors?
Author: Ashish
6. The Ultimate Guide To Ebay Product Listing Services: Elevate Your Online Store
Author: rachelvandereg
7. Which Are The Best Java Coding Classes In Bhopal?
Author: Shankar Singh
8. Warehouse Management In Zambia: Essential Features To Look For
Author: Doris Rose
9. Ecommerce Web Design And Development In Melbourne With The Merchant Buddy
Author: themerchantbuddy
10. Why Website Maintenance Is Crucial For Business Success
Author: Yogendra Shinde
11. Boost Your Business With Smart Invoice Pos Software In Zambia
Author: Cecilia Robert
12. How Stablecoin Development Ensures Stability And Security?
Author: Michael noah
13. Công Cụ Tính Chiều Cao Chuẩn Từ Minbin Tool: Đo Lường Và Cải Thiện Chiều Cao Hiệu Quả
Author: KenJi123
14. How To Make A Courier App For Courier Delivery And Tracking Service
Author: Deorwine Infotech
15. Reputation Management In The Digital Age: Protecting And Enhancing Your Law Firm’s Image
Author: jamewilliams