![]() |
| ||
| exceptions ehat is the differencde between error,checked exception and unchecked exception?when occurs at what time?compile time or runtime?which of them can be handled and what not handled?example? |
| ||
| Re: 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. |
| ||
| Re: exceptions 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). |
| ||
| Re: exceptions Error (since 1.5) is another "excpetion" class. Here a quote from the API Quote:
|
| All times are GMT -4. The time now is 10:24 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC