Exception in Programming

414 words | 2 page(s)

In programming, the term “exception” refers to an event whose occurrence impacts on the normal flow of instructions of the program. The occurrence of an error in a method will result in the creation of an object that will be directed to the runtime system, a process referred to as “throwing an exception.’ The exception object will then come up with the information that explains the error that has been experienced encompassing the state as well as the type of the program after the apparent occurrence of the error.

In programming, exceptions are typically classified into either checked or unchecked exceptions. The primary difference between the two types of exceptions lies on the basis that checked exception is usually checked at what can be described as compile-time whereas the unchecked exception is essentially checked at runtime. In checked exception, the moment the checked exception is thrown by a method, the method tackles the exception with the help of a try-catch block or declares it via throws keyword (Van, Marko, and Eric, 2000). Through the declaration of exception using throws keyword, we can show an example of a checked exception

puzzles puzzles
Your 20% discount here.

Use your promo and get a custom paper on
"Exception in Programming".

Order Now
Promocode: custom20

Import java.io.*;
Class Example {
Public static void main (string args [{
FileUnpitStream fis= null;
fis = new FileInpitStream(“B:/myfi int k;
while(( k =fisread() ) !+ -1)
{
System.out.print((char)k);
}
Fis.close( );
}
}

The generated content will then be visible on the screen

Unlike a checked exception, the unchecked exception is not checked at compile-time. When a program throws an unchecked exception, even if the exception is not declared, the program will not come up with a compilation error. In most scenarios, an unchecked exception is likely to be experienced as a result of bad data from the user of the program. Therefore, it is the duty of the programmer to gauge the condition that can lead to unchecked exceptions in advance and tackle them effectively (Van, Marko, and Eric, 2000). An unchecked exception can be represented as follows:

Class Example {
Public static void main (string args [{
Int num1 = 10;
Int num2 = 0;
/*since an integer is being divided
* ArthmeticExc should be thrown
Int res= num1/num2;
System.out.ptintIn(res);
}
}

When one compiles the code above, it will be successful but will throw ArthmeticException clearly showing that unchecked exceptions are thrown at runtime as opposed to compile-time.
Source: (Van, Marko, and Eric, 2000).

    References
  • Van Dooren, Marko, and Eric Steegmans. “Combining the robustness of checked exceptions with the flexibility of unchecked exceptions using anchored exception declarations.” ACM SIGPLAN Notices 40.10 (2005): 455-471.

puzzles puzzles
Attract Only the Top Grades

Have a team of vetted experts take you to the top, with professionally written papers in every area of study.

Order Now