Monday, August 18, 2014

Difference between bug, error and exception

"One of the most confusing question I would say".
I have a story to simplify these three concepts:
Suppose I planned to go from India to London. Took my flight from New Delhi Airport for London. I kept in my mind the time when the flight will land in London. But when I woke-up, I was in Dubai. This is called Bug. Irrelevant result. Everything looks fine but the output is not as expected. 

Second one is ERROR: When I reached the airport to take my flight, there was some problem in the Air-Bus due to which the flight got delayed. This problem is called error and without fixing it, we are not able to execute the code. We have to fix it first.

And the last one is EXCEPTION. Let's suppose when I'm in the flight, and mid-way, all the engine of the plane stopped working due to unexpected reasons but I landed safely. Common belief would be that the plane is going to be crashed but this did not happen and all the passengers are safe. This is called EXCEPTION.  I'm still alive and running.

Same thing happens in a Program also. You don't come to know that some circumstances are generated in your program and by these circumstances, you believed that the program will surely crash/Stop but it did not happen. Because these exceptions are handled in our code.

For e.g. suppose a SQL Connection Exception Occurred and you don't know  when your database is  going to crash. By these exceptions,your program will definitely crash and a Big Yellow page will come at user's end. To manage this, we need to handle these exception in our program to run the program hassle free.

So we can say that: exception handling features provide a way to deal with any unexpected or exceptional situations that arise while a program is running.


No comments:

Post a Comment