-
January 2nd, 2017, 05:40 PM
#1
Difference between Errors and Exceptions? (newbie)
What's exactly the difference between an error and an exception(in detail if possible)
Thanks
-
January 19th, 2017, 12:24 AM
#2
Re: Difference between Errors and Exceptions? (newbie)
An Error indicates serious problems that a reasonable application should not try to catch and an Exception indicates conditions that a reasonable application might want to catch. Unchecked exceptions are those exceptions that might not happen if everything is in order, but they do occur. Examples include ArrayIndexOutOfBoundException etc. Checked exceptions are generally those from which a program can recover & it might be a good idea to recover from such exceptions programmatically. Examples include FileNotFoundException For catching the exceptions we use try-catch clause.
Example of Exception code:
try
{
//connect to database 1
}
catch(DatabaseConnctionException err){
//connect to database 2
//write the err to log
}
Error are unchecked exceptions and the programmers do not have to do anything with it and it is a bad idea to try to catch errors with exceptions. The program cannot recover from the errors and the program should be allowed to terminate.
Examples of error include OutOfMemoryError, StackOverflowError, etc.
Claire
-
January 24th, 2017, 02:38 PM
#3
Re: Difference between Errors and Exceptions? (newbie)
Also read the API doc for the Error and Exception classes for more info.
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|