Reputation: 685
In general I want to know what is the difference between bug and exception?
If I need to be specific for a particular framework then I would like to go with .Net.
Upvotes: 1
Views: 5783
Reputation: 2858
Bug - an unhandled error in a program's behavior that leads to unexpected behavior or an exception. For example: A calculator responding with 55
for 5+5
because you forget to convert the string to a number. In this case, unexpected behavior is presented (as the exception is not handled).
Exception - an internal error intentionally thrown and one that can and should be caught. For example: A user enters the name of a file for reading, but the file itself is missing. The file reading method throws a FileNotFoundException
, but you catch this exception and send a message to the user that the entered file does not exist.
Unhandled exception - a bug. For example: In a calculator, a user inputs 5/0
, and the division operation throws a ZeroDivisionError
exception. If you don't handle it, your program will simply crash. In this context, fixing the bug means handling this exception - adding a method to catch this exception using try
and except
to display an error message to the user.
Upvotes: 0
Reputation: 137178
An exception is an exceptional but expected circumstance, something that's rare but could happen for a variety of reasons. Obvious examples include cases where a file (e.g. log file) can't be found, or the user input doesn't convert to a integer.
A bug is an error in the code that produces an incorrect result - which may or may not raise an exception.
Some examples of bugs:
You do some calculation and due to rounding errors (say) the output is "23.9" rather than "24". This would be a bug but doesn't raise an exception.
You build a file name, but get the path wrong which causes a "file not found" exception. This could be bug, but would raise an exception.
Upvotes: 4
Reputation: 31
Difference between Bugs, Exceptions and End User Errors
By Dhaval Patel
Humans are bound to make errors, and programmers are humans. Applications may crash or stop running because of different reasons. The crash may happen during the application development OR during production when the application is already released. Now this hiccup may be categorized in three ways:
1) Bugs - When the cause of the error is because of a mistake done by a developer, its called a bug. A developer may be well experienced but still may write bad code by mistake. For instance, a declared file object may not be disposed, and may later cause a memory leak, well thats a bug. Normally, during development of enterprise applications, bugs are caught by Testers and categorized based on their criticality. But there may be times when even the Testing team might miss out on catching a bug. Well, thats danger!
2) Exceptions - An exception may be a System Exception or an Application Exception. Now say, a file being parsed by the code has been deleted by some one from the location being searched, then a "File Not Found" exception may crop up. Such exceptions are usually handled by well written code by using Exception Handlers. These errors are usually caused at runtime. They may be difficult to prevent at times, but surely may be handled by good code. There might be a scene where the programmer may only catch the exception through good code but may not prevent it.
3) End User Errors - An error may be invoked by an input made by the end user. For example, an invalid string may be entered in a Textbox that expects a number. These types of errors may be handled using controls like RegularExpressionValidator, or code that handles the keyboard, mouse, stylus input. These errors if not handled efficiently by the developer, may cause terrible nightmares. For example, an application may be hacked or damaged using SQL injections, if at all, input boxes allow bad input that may crack the code.
The three points above are the broad categories into which errors may be divided.
Happy Programming.
Cheers!
Upvotes: 3
Reputation: 1039238
Errors in your code could provoke exceptions to be thrown at runtime or even prevent your code from compiling if you have syntax errors. So basically the first is the cause for the second or the second is a consequence of the first.
Upvotes: 0