开发者

What's the difference between a bug and an exception?

In general I want to know what is the difference between 开发者_如何学JAVAbug and exception?

If I need to be specific for a particular framework then I would like to go with .Net.


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:

  1. 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.

  2. 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.


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜