CHAPTER 7.1 :- ERROR HANDLING

An Exception occurs when a program encounter any unexpected problems. Such as running out of memory or attempting to read from a file that no longer exists. These problems are not necessarily caused by a programming error but they mainly occur be cause of violation of assumption that you might have made about the execution environment. When a program encounters an exception the default behavior is to throw the exception which generally translates to abruptly, terminating the program after displaying an error message. But this is not a characteristic of a robust application.

But the best way is to bindle the exception situations if possible, gracefully recover from them. This is called “exception handling”.

I used try, catch, finally and throw in my project to handle the exception.

The Try Block:

Place the code that might cause exception in a try block. A typical try block looks like this

Try

{

//Code that may cause exception

}

A try block can have another try block inside when an exception occurs at any point rather than executing any further lines of code, the CLR (Common Language Runtime)

Secures for the nearest try block that enclosure this code. This code. The control is then passed to a matching catch block if any and then to the kindly block associated with this try block.

Catch Block:

There can be no of catch blocks immediately following a try block. Each catch block handles an exception of a particular type. When an exception occurs in a statement placed inside the try block the CLR looks for a mainly block that is capable of handling the type of exception.

Throw block:

A throw statement explicitly generates an exception in code. You can throw when a particular path in code results in an anomalous situation.

Finally Block:The finally block contains the code that always executes whenever or not any exception occurs.