This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi, Thanks in advance. In java we can create our own exception. And Java exceptions are mainly divided into two Checked and Unchecked if so, the exception which is created by own will be what type (checked/unchecked).
If your new exception class extends java.lang.Exception, it is a checked exception. In general, your user-defined exceptions should be checked exceptions.
If your new exception class extends java.lang.RuntimeException, it is an unchecked exception. Unchecked exceptions are generally for situations that cannot occur, when the code is working properly - i.e. for indicating bugs.
If your new exception class extends java.lang.Error, it is an Error. Errors are for fatal system problems (e.g. out-of-memory) and are unchecked; there are few valid reasons to define a new Error, but it is legal to do so, if you find a reason.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
If the Exception you create extends any other sort of Exception and doesn't extend RuntimeException = checked. Example: EthernetWireMissingException extends IOException doesn't extend RuntimeException directly or indirectly. Another example: SridharsNewException extends Exception = checked.
Peter's description of when to use checked and unchecked fits Sun's intentions when they invented them. That's a perfectly good way to operate and probably good advice for now. But be aware that not everyone agrees and you may well run into applications written with unchecked exceptions. If you find some code like that, read it carefully and see if you think it worked out better or worse in the long run.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi