Types of Exceptions in Java: Java API के Methods व जावा स्वयं भी विभिन्न प्रकार के Exceptions Throw करता है। इन Exceptions को दो Sub Classes Error व Exception में विभाजित किया जा सकता है। इन दोनों 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
Exception | Cause |
ArithmeticException | Arithmetic error condition (for example, divide by zero). |
ArrayIndexOutOfBoundsException | Array index is less than zero or greater than the actual size of the array. |
ArrayStoreException | Object type mismatch between the array and the object to be stored in the array. |
ClassCastException | Cast of object to inappropriate type. |
ClassNotFoundException | Unable to load the requested class. |
CloneNotSupportedException | Object does not implement the cloneable interface. |
Exception | Root class of the exception hierarchy. |
IllegalAccessException | Class is not accessible. |
IllegalArgumentException | Method receives an illegal argument. |
IllegalMonitorStateException | Improper monitor state (thread synchronization). |
IllegalThreadStateException | The thread is in an improper state for the requested operations |
IndexOutOfBoundsException | Index is out of bounds. |
InstantiationException | Attempt to create an instance of the abstract class. |
InterruptedException | Thread interrupted. |
NegativeArraySizeException | Array size is less than zero. |
NoSuchMethodException | Unable to resolve method. |
NullPointerException | Attempt to access a null object member. |
NumberFormatException | Unable to convert the string to a number. |
RuntimeException | Base class for many java.lang exceptions. |
SecurityException | Security settings do not allow the operation. |
StringIndexOutOfBoundsException | Index is negative or greater than the size of the string. |
The java.lang Errors
Error | Cause |
AbstractMethodError | Attempt to call an abstract method. |
ClassCircularityError | This error is no longer used. |
ClassFormatError | Invalid binary class format. |
Error | Root class of the error hierarchy. |
IllegalAccessError | Attempt to access an inaccessible object. |
IncompatibleClassChangeError | Improper use of a class. |
InstantiationError | Attempt to instantiate an abstract class. |
InternalError | Error in the interpreter. |
LinkageError | Error in class dependencies. |
NoClassDefFoundError | Unable to find the class definition. |
NoSuchFieldError | Unable to find the requested field. |
NoSuchMethodError | Unable to find the requested method. |
OutOfMemoryError | Out of memory. |
StackOverflowError | Stack overflow. |
ThreadDeath | Indicates that the thread will terminate. May be caught to perform cleanup. (If caught, must be rethrown.) |
UnknownError | Unknown virtual machine error. |
UnsatisfiedLinkError | Unresolved links in the loaded class. |
VerifyError | Unable to verify bytecode. |
VirtualMachineError | Root 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
Exception | Cause |
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
Exception | Cause |
MalformedURLException | Unable to interpret URL. |
ProtocolException | Socket class protocol error. |
SocketException | Socket class exception. |
UnknownHostException | Unable to resolve the host name. |
UnknownServiceException | Connection 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)
ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook Java in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी।
Java Programming Language in Hindi | Page: 682 | Format: PDF