| | |
exceptions
![]() |
A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method·
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the
exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method·
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the
exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.
Adios,
Vinod......
Vinod......
Error: Assuming you refer to error codes, these would be errors given to caller of a function via return types.
Checked Exception: Exceptions that are checked by compiler at compile time are the checked exceptions. Means if you are not handling a checked exception of a method you call, compiler would give an error.
These are derived from Exception class.
Unchecked Exception: Exceptions that are NOT checked by compiler at compile time. THese are derived from RuntimeException
If you are trying to decide whether you should derive your own exception class from RuntimeException or Exception, then the rule of thumb would be to see if this is:
- If you are throwing the exception because your function is unable to do it's own work throw a checked exception.
- If you are throwing the exception because of some external factors which don't anything to do with the functionality of your code throw an unchecked exception. (E.g. IllegalArgumentException).
Checked Exception: Exceptions that are checked by compiler at compile time are the checked exceptions. Means if you are not handling a checked exception of a method you call, compiler would give an error.
These are derived from Exception class.
Unchecked Exception: Exceptions that are NOT checked by compiler at compile time. THese are derived from RuntimeException
If you are trying to decide whether you should derive your own exception class from RuntimeException or Exception, then the rule of thumb would be to see if this is:
- If you are throwing the exception because your function is unable to do it's own work throw a checked exception.
- If you are throwing the exception because of some external factors which don't anything to do with the functionality of your code throw an unchecked exception. (E.g. IllegalArgumentException).
Error (since 1.5) is another "excpetion" class. Here a quote from the API
•
•
•
•
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- C++ / Exceptions (C++)
- Exceptions (repost) (C++)
- Exceptions (C++)
- weird exceptions:( (Python)
- How to handle exceptions in constructor? (Java)
- Exceptions (Java)
- Arithmetic Exceptions and exception-handling statements (Java)
Other Threads in the Java Forum
- Previous Thread: Oregon Trail In Java!!
- Next Thread: J-Creater installation probrem
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows






