232 Part II Programming Fundamentals
The SizeMode property of the picture box object is set to StretchImage, so the file fills
the entire picture box object. Now see what happens when the CD or DVD isn’t in the
drive when the program attempts to load the file.
- Remove the CD or DVD from the drive.
If you are using a different media type, remove it now. If you are testing with a
removable storage device, follow your usual procedure to safely remove or turn it off,
and remove the media containing Fileopen .bmp.
- Click the Check Drive button again on the form.
The program can’t find the file, and Visual Basic issues a run-time error, or unhandled
exception, which causes the program to crash. Visual Studio enters debugging mode,
highlighting the problem statement.
Your screen will look like this:
Notice how helpful Visual Studio is trying to be here, by offering troubleshooting
tips to assist you in locating the source of the unhandled exception that has stopped
the program. The Actions list allows you to learn even more about the specific error
message that is displayed at the top of the dialog box.
- Click the Stop Debugging button on the Standard toolbar to close the program.
The development environment returns.
Now you’ll modify the code to handle this plausible error scenario in the future.