Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the program, exception handling will be used to deal with input or output err

ID: 3674036 • Letter: I

Question

In the program, exception handling will be used to deal with input or output errors.

What are the advantages and disadvantages of testing for error conditions as compared to using exception handling when performing input or output?

Why have almost all programmers, in almost all cases, moved to using exception handling for input or output?

In what situations other than input or output might find exception handling useful?

Could exception handling be the preferred approach to use for those situations as well?

Explanation / Answer

Advantages of Exception Handling

1. Exceptions separate error-handling code from the normal program flow and thus make the code more readable, robust and extensible.

2. Throwing an exception is the only clean way to report an error from a constructor.

3. Exceptions are hard to ignore, unlike error codes.

4. Exceptions are easily propagated from deeply nested functions.

5. Exceptions can be, and often are, user defined types that carry much more information than an error code.

6.Exception objects are matched to the handlers by using the type system.

Disadvantages of Exception Handling

1. Exceptions break code structure by creating multiple invisible exit points that make code hard to read and inspect.

2. Exceptions easily lead to resource leaks, especially in a language that has no built-in garbage collector and finally blocks.

3. Learning to write exception safe code is hard.

4. Exceptions are expensive and break the promise to pay only for what we use.

5. Exceptions are hard to introduce to legacy code.

6. Exceptions are easily abused for performing tasks that belong to normal program flow.

Almost all programmers, in almost all cases, moved to using exception handling for input or output because input and output are unreliable.

Exceptions are, in part, an acknowledgement that there are going to be conditions which the software cannot reasonably recover from.

Exceptions are the programmer's way of saying "I can't continue under the present conditions." In essence, when you throw an exception, you're giving up and asking for a do-over.

We can do this without gracefully exiting your input/output subroutine or even worrying about memory management, because the orderly disposal of the relevant objects is already built into the exception-handling mechanism.

1. Exception Handling is useful for the programmers. It is used to handle exceptions like divide by zero exception, array index out of bounds exception, number format exception, extra.

2. For example, unexpectedly user wants to perform any number divided by zero. if user uses exception handling concept in the program, it reports an error message.

1. Exception handling concept is very useful concept for the users who wants to write programs in c++, Java. This concept is not available in c.

2. Without exception handling, we cannot catch the exceptions.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote