Vote Up 0 Vote Down

difference between errors and exceptions in java

What is the difference between Errors, Exceptions?
And why do we use Exception Handling?


Vote Up 0 Vote Down
There are 3 kinds of errors.
1. Syntax errors. The program code breaks the grammar rules of the language. The compiler will detect these and tell you. These are easy, but common for beginners
2. Runtime errors. The program crashes when its run. Doesn't happen with Java - you get an exception instead
3. Logic errors. Program compiles and runs - but the result is wrong. These are the tricky ones. Needs careful debugging.

An exception is an unusual event at runtime. Most causes are external - user enters invalid data, network connection fails, disc drive fails. Some causes internal - you run out of memory.
We use exception handling to try to recover the program. Like if the user enters invalid data, tell them and try again. If the disk drive fails - ask the user to suggest a different drive.
Some exceptions cannot be recovered from - like the JVM goes wrong. Execution ends with teh exception reported.
flag | link |

Your Answer

Login before answering

Login with facebook