What are Bugs, Errors and Exceptions in Programming?

Bug

A bug is a mistake made by the programmer that should be fixed before the code is sent for production. A bug might cause an exception to be thrown. But the programmer should not rely on exceptions to handle the bugs. When found all the bugs should be fixed.

Error

An error is caused by the action of the user. For example, the user might enter a letter where a number is expected. An error can also result into an exception but that can be prevented by do doing proper validation. Whenever possible, errors should be anticipated and prevented.

Exception

In object-oriented programming, an exception is an object that encapsulates information about an unusual program occurrence.

Even after removing all bugs and anticipating all user errors, the program can still run into unpredictable problems like running out of memory or attempting to open a file that no longer exists. Such problems cause exceptions to be thrown by the program.

Thus you cannot prevent exceptions, but you can handle them so that they do not bring down your program.