Bugs are an unfortunate evil in software. This is not because developers are necessarily bad, or that we write bad code, it’s just that sometimes we can’t think of everything that could possibly happen when users are involved. And as you know, users are the main reason that your programs might crash, not the code. Besides, what would Quality Assurance people do if we all wrote perfect code?
Exception is a runtime error that arises due to some specific conditions that contradict a specified or implied constraint, such as division of a number by zero or passing a string to a variable that holds an integer value. Errors are usually raised at compile time and can be handheld before executing the application. In VB.NET, the terms exception handling and error handling can be used interchangeably, because both result in the termination of an application with a choice of debugging the exceptions or errors. Capturing and handling of runtime errors is one of the important and crucial tasks for any programmer. However, we discuss runtime errors, let us discuss about the types of errors that crop up (appears unexpectedly) during making any application.
1. Design time errors
2. Runtime errors
3. Logic errors
Design Time Errors
· Also called the syntax errors, design-time errors occur when you write a piece of code that does not conform to the rules of the language in which you are writing.
· Some design-time errors are simply typological errors, where you have mistyped a keyword. Others are the result of missing items: undeclared or untyped variables, classes not yet imported, incorrect parameters lists in function or method call, or referencing members of a class that do not exist.
· A program with as few as one design-time error cannot be compiled and run – you must locate and correct the error before continuing.
· Fortunately, design-time errors are the easiest to detect and correct, because VB.NET shows you the exact location of these errors and gives you good information about what part of the code it can’t be understand.
The event code shown below makes you understand that what happens if any unexpected error occurs:
Code:
Output window:
The above figures displays that when you type the code, automatically the compiler shows you one squiggly line. This indicates that the word which you have typed doesn’t match with any built-in word in libraries of VB.NET. So while compiling the code, the IDE prompts you with a message that “Consol is not declared”. It even gives you the exact line and column number where the error had occurred through which you can easily rectify the error.
Runtime Errors
Runtime errors are much more insidious to find and fix than design-time errors. Runtime are problems encountered by your program while it’s running. Runtime errors can take on dozens of different shapes and forms. Here are some examples:
· Attempting to open a file that doesn’t exist.
· Trying to log in to a server with an incorrect username or password.
· Trying to access a folder for which you have insufficient rights.
· Requesting data from a database table that has been renamed.
· Opening a file on server that is down for maintenance.
· Accessing an Internet URL that no longer exists.
· Allocating a resource without the necessary available RAM.
· Dividing a number by zero.
· Users entering character data where a number is expected (and vice versa)
As you can see, runtime errors can occur due to an unexpected state of the computer or network upon which your program is running, or simply because the user has supplied the wrong information (an invalid password, a bad file name, and so on). Because of this, you can write a program that runs fine on your own machine, and all the machines in your test environment, but fails on a customer site due to the state of the customer’s computing resources.
As you might imagine, runtime errors can be many degrees harder to diagnose and fix in comparison to design-time errors. After all, any error you make in design time is right there in front of you, on your own development PC. Not only that, but the Visual Studio compiler goes ahead and tells you right where a design-time error is and why it’s an error.
Logic Errors
Logic errors also occur at runtime, and because of this, they are often difficult to track down. A logic error occurs when a program does not do what the developer intended it to do. For example, you might provide to add a customer to a customer list, but when the end user runs the program and adds a new customer, the customer is not there. The error might lie in the code that adds the customer to the database; or perhaps the customer is indeed being added, but the grid that lists all the customers is not being refreshed after the add customer code, so it merely appears that the customer wasn’t added.
Resources Used:
1. Visual Basic .NET (Bible)
2. VB.NET (Mastering)
3. VB.NET How to Program (Deitel)
4. Programming in VB.NET (Bradely)
Compiled By: Chaudhary Amit V.


Comments
Post a Comment