Types of Exceptions in Java

Types of Exceptions in Java: Java API के Methods व जावा स्वयं भी विभिन्न प्रकार के Exceptions Throw करता है। इन Exceptions को दो Sub Classes ErrorException में विभाजित किया जा सकता है। इन दोनों Sub Classes को Throwable Super Class से Derive किया गया है। Error Class व इसकी Sub Classes ऐसी स्थितियों को Represent करते हैं, जिन्हें सामान्‍यतया Solve नहीं किया जा सकता है और सामान्‍यतया ये हमारे Program को Terminate ही करते हैं। Java Developer Kit की विभिन्न Classes विभिन्न प्रकार के Exception व Error Exceptions Throw करते हैं।

java.lang Exceptions

इस Package में जावा Language की ज्यादातर आधारभूत Classes हैं, जिन पर जावा आधारित है। इन Classes को “Core of Java” Language भी कहा जाता है। RuntimeException Class से Derive किए गए किसी भी Method के साथ throws Keyword का प्रयोग करके Exception को Throw करने की जरूरत नहीं होती है। इनसे Generate होने वाले Exceptions Normal Exceptions कहलाते हैं और सामान्‍यतया इन Exceptions को कोई भी Method Throw कर सकता है।

किसी Program में Generate होने वाली वे Abnormal स्थितियां जिन्हें Solve किया जा सकता है, Exception कहा जाता है, जबकि जिन स्थितियों को Solve नहीं किया जा सकता है, उन्हें Errors कहते हैं। Exceptions Recoverable होते हैं जबकि Errors Non-Recoverable होते हैं। निम्न Table में java.lang Package से Generate हो सकने वाले विभिन्न Exceptions व Errors को उनके Short Description के साथ दर्शाया गया है:

The java.lang Exceptions

ExceptionCause
ArithmeticExceptionArithmetic error condition (for example, divide by zero).
ArrayIndexOutOfBoundsExceptionArray index is less than zero or greater than the actual size of the array.
ArrayStoreExceptionObject type mismatch between the array and the object to be stored in the array.
ClassCastExceptionCast of object to inappropriate type.
ClassNotFoundExceptionUnable to load the requested class.
CloneNotSupportedExceptionObject does not implement the cloneable interface.
ExceptionRoot class of the exception hierarchy.
IllegalAccessExceptionClass is not accessible.
IllegalArgumentExceptionMethod receives an illegal argument.
IllegalMonitorStateExceptionImproper monitor state (thread synchronization).
IllegalThreadStateExceptionThe thread is in an improper state for the requested operations
IndexOutOfBoundsExceptionIndex is out of bounds.
InstantiationExceptionAttempt to create an instance of the abstract class.
InterruptedExceptionThread interrupted.
NegativeArraySizeExceptionArray size is less than zero.
NoSuchMethodExceptionUnable to resolve method.
NullPointerExceptionAttempt to access a null object member.
NumberFormatExceptionUnable to convert the string to a number.
RuntimeExceptionBase class for many java.lang exceptions.
SecurityExceptionSecurity settings do not allow the operation.
StringIndexOutOfBoundsExceptionIndex is negative or greater than the size of the string.

The java.lang Errors

ErrorCause
AbstractMethodErrorAttempt to call an abstract method.
ClassCircularityErrorThis error is no longer used.
ClassFormatErrorInvalid binary class format.
ErrorRoot class of the error hierarchy.
IllegalAccessErrorAttempt to access an inaccessible object.
IncompatibleClassChangeErrorImproper use of a class.
InstantiationErrorAttempt to instantiate an abstract class.
InternalErrorError in the interpreter.
LinkageErrorError in class dependencies.
NoClassDefFoundErrorUnable to find the class definition.
NoSuchFieldErrorUnable to find the requested field.
NoSuchMethodErrorUnable to find the requested method.
OutOfMemoryErrorOut of memory.
StackOverflowErrorStack overflow.
ThreadDeathIndicates that the thread will terminate. May be caught to perform cleanup. (If caught, must be rethrown.)
UnknownErrorUnknown virtual machine error.
UnsatisfiedLinkErrorUnresolved links in the loaded class.
VerifyErrorUnable to verify bytecode.
VirtualMachineErrorRoot class for virtual machine errors.

java.io Exceptions

java.io Package की Classes भी विभिन्न प्रकार के Exceptions Throw करती हैं, जिन्हें आगे थोडे से Description के साथ दर्शाया गया है। कोई भी ऐसी Class जो I/O के लिए Use की जाती है, Recoverable Exceptions Throw कर सकती है। उदाहरण के लिए किसी File को Open करने या File में Write करने की Process समय-समय पर Fail होती रहती है। java.io Package किसी प्रकार का Error Throw नहीं करता है।

The java.io Exceptions

ExceptionCause
IOException Root class for I/O exceptions.
EOFException End of file.
FileNotFoundException Unable to locate the file.
InterruptedIOException I/O operation was interrupted. Contains a bytesTransferred member that indicates how many bytes were transferred before the operation was interrupted.
UTFDataFormatException Malformed UTF-8 string.

java.net Exceptions

ये Package Network Communications को Handle करता है। ये Class सामान्‍यतया ऐसे Exceptions Generate करता है, जो Connect Failure या इससे सम्बंधित जानकारियां प्रदान करते हैं। ये Package भी कोई Error Throw नहीं करता है, लेकिन ये Package निम्नानुसार कुछ Exceptions Throw करता है:

The java.net Exceptions

ExceptionCause
MalformedURLExceptionUnable to interpret URL.
ProtocolExceptionSocket class protocol error.
SocketExceptionSocket class exception.
UnknownHostExceptionUnable to resolve the host name.
UnknownServiceExceptionConnection does not support the service.

The java.awt Exceptions

इस Class में ऐसे Members हैं जिनमें से एक तो Error Throw करता है जबकि दूसरा Exception Throw करता है। ये Members निम्नानुसार हैं:

  • AWTException    ( ये Class AWT Class की Exceptions को Throw करता है। )
  • AWTError             ( ये Class AWT Class की Errors को Throw करता है। )

The java.util Exceptions

इस Package की Classes निम्न Exceptions Throw करता है:

  • EmptyStackException                  (no objects on stack)
  • NoSuchElementException          (no more objects in collection)
try catch finally
Java Custom Exception

Java Programming Language in Hindiये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook Java in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी। 

Java Programming Language in Hindi | Page: 682 | Format: PDF

BUY NOW GET DEMO REVIEWS

MidRangeHub Finance Auto Loans Bank Business Health Insurance Insurance Investment Law Lif Insurance Loan Stocks how to endorse a check chase sapphire travel insurance chase sapphire travel delay when are property taxes due Tower Loans how to sell stocks on cash app Voided Check Examples Personal Finance Books Collateral Loans how to sell stocks on cashapp how do you sell your stocks on cash app how to sell stock on cash app joint account sofi joint account ally joint account capital one joint account best bank for joint account chase joint account cyber insurance coverage silverfort free cyber insurance coverage silverfort monjouro savings card Money6x Real Estate