Exception – an Abnormal Event in Program
Essay Preview: Exception – an Abnormal Event in Program
Report this essay
Introduction
An exception is an abnormal event that is likely to happen when a program is executing. For instance:
The computer could run out of memory. Not usually, but there is a possibility that it can happen.
Calling the parseInt( arg ) method with argument, arg, that cannot be parsed into an integer.
Dividing an integer value by zero.
Using an index that is outside the range of an array.
Accessing an ArrayList or a Vector that is empty.
Attempting to access a file that does not exists.
Attempting to access a file that is empty.
Exception must be distinguished from other types of programming errors. Programming errors can be categorized into three types – syntax errors, logic errors, and runtime errors. Errors that occur during compilation are called syntax errors or compilation errors. These errors result from the lack of compliance with the rules of the programming language. Logic errors on the other hand occur when the program produces unintended results. Runtime errors occur when the program attempts to perform tasks that are impossible. Against this background the program terminates abnormally. If we analyze the examples above, we will see that those tasks are impossible to done, hence, they are all runtime errors.

The concept of exception is a customary way in Java to indicate that an abnormal condition has occurred. When a method encounters an abnormal condition that it cannot handle itself, it may throw an exception. Throwing an exception is like tossing a ball out of a window hoping that there is someone outside there who will catch it.

The central mission of exception handling is to transfer control from where the error occurred to a section of the program that can deal with the exception. The section of code that deals with the exception is called an exception handler. When you program in Java, you must position exception handlers strategically, so that your program will catch and handle all exceptions that are likely to be thrown.

Response to an Exception
A program can be made to:
Ignore exceptions, in which case the program would abort, or produce incorrect result.
The user could be allowed to fix the problem, but usually the user of the program is not a programmer.
The programmer could design the program in such a way that if and when an exception occurs, program control would pass the exception to an appropriate block of codes within the program where the exception can be taken care of.

Get Your Essay

Cite this page

Types Of Programming Errors And User Of The Program. (July 7, 2021). Retrieved from https://www.freeessays.education/types-of-programming-errors-and-user-of-the-program-essay/