Exceptions “against” Errors

Common misconception during programming

In java, both ‘Exceptions’ and ‘Errors’ are subclasses of “java.lang.throwable” class.
Error refers to an illegal operation performed by the user which results in abnormal behavior of the program. Programming errors many a time remain undetected until the program is executed or compiled. Some errors inhibit the program from getting executed. Thus making it necessary to remove errors before compiling or executing. Errors are of three types:

  • Compile-time errors
  • Run-time errors
  • Logical errors

Compile-time errors
Compile-time errors are those errors which prevent the code from running because of an incorrect syntax such as a missing semicolon at the end of a statement or a missing bracket, etc. These errors are detected by the java compiler and an error message is displayed onto the screen while compiling. Compile-time errors are also referred to as “Syntax errors”.

Run-time errors
Run-time errors occur during the execution of the program. Sometimes these are discovered when the user enters an invalid data or data which is not relevant. Run-time errors occur when a program does not contain any syntax errors but asks the computer to do something that the computer is unable to reliably do. The compiler has no technique to detect these kind of errors. It is the JVM (Java Virtual Machine) which detects it while the program is running.

Logical errors
When the program compiles and executes, but does the wrong thing or returns an incorrect result or shows no output; it is a logical error. These errors are neither detected by compiler nor by JVM. The system has no idea what the program is supposed to do, so it provides an additional information to help find the error. Logical errors are also called Semantic errors.

Exceptions in java refer to an unwanted event, which occurs during the execution of a program, i.e. at run-time, that disrupts the normal flow of the program’s instructions. Exceptions are the conditions that occur at runtime and may cause the termination of the program. But they are recoverable using try, catch and throw keywords. Exceptions are divided into two categories:

  • Checked exceptions
  • Un-checked exceptions

Checked exceptions are like IOException known to the compiler at compile time .
Un-checked exceptions are like ArrayIndexOutOfBoundException known to the compiler at runtime, mostly caused by the program written by programmer.

原文链接:Exceptions “against” Errors

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容