answersLogoWhite

0

Exception is a event which can interrupt a normal flow of your program. In other way, exception is a abnormal condition which can occur during the execution of a program. Yes , we can handle exceptions through try, catch, finally, throw and throws.

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
ReneRene
Change my mind. I dare you.
Chat with Rene
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
More answers

Throwing an exception means create a new exception to notify the program that a unexpected condition was occurred.

Catch an exception refers to handle that unexpected condition and allow the program continue its normal execution.

User Avatar

Wiki User

14y ago
User Avatar

Exceptions are special errors or situations (sometimes programmer-defined) that interrupt normal program flow.

In C#, thrown exceptions will remain unhandled (and will usually give a general error message) unless handled by a try-catch block, like this:

try

{

// execute instructions that can possibly thrown an exception

}

catch (Exception ex)

{

// Here we handle the exception, using whatever we need from

// Exception object, such as ex.Message or ex.StackTrace.

}

finally

{

// This section is called regardless of whether an exception was thrown

// or not. The end result of both the try and catch blocks' execution is

// this block.

}

User Avatar

Wiki User

12y ago
User Avatar

Language compilers are adept at pointing out most of the erroneous code in a program, however there are some errors that only become apparent when the program is executed. Consider the code in Listing 1.1; here, the program defines a method dividethat does a simple division operation taking two integers as parameter arguments and returning the result of their division. It can safely be assumed that when the divide(4, 2)statement is called, it would return the number 2. However, consider the next statement, where the program relies upon the provided command line arguments to generate a division operation. What if the user provides the number zero (0) as the second argument? We all know that division by zero is impossible, but the compiler couldn't possibly have anticipated the user providing zero as an argument.

User Avatar

Wiki User

12y ago
User Avatar

By using exception handling we can avoid unwanted unwanted results on our page. On places where we know our code may execute in an unwanted fashion, we can surround it with exception handling block to ensure that our code doesnt disrupt the application flow.

For example:

In a text field where you enter amounts and use it in our code we parse it as a number. But if the user enters any invalid numbers, while parsing an exception would be thrown and our program would terminate. We can avoid this by using the try catch block.

public int parseStringToNum(String value) {

int val;

try {

val = Integer.parseInt(value);

} catch (Exception e){

val = 0;

}

return val;

}

Here even if the value entered is invalid only a 0 will be returned and no exception would be thrown.

User Avatar

Wiki User

16y ago
User Avatar

Exception handling helps us catch or identify abnormal scenarios in our code and handle them appropriately instead of throwing up a random error on the front-end (User Interface) of the application.

Exception handling allows developers to detect errors easily without writing special code to test return values. Even better, it lets us keep exception-handling code cleanly separated from the exception-generating code. It also lets us use the same exception-handling code to deal with a range of possible exceptions.

User Avatar

Wiki User

11y ago
User Avatar

special processing of unexpected events inside the program. events outside the program are processed by interrupts, not exceptions.

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is exception handling in object oriented languages?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering