October 2008
Beginner to intermediate
680 pages
16h 48m
English
Exceptions are a way for the .NET runtime to signal that something has gone wrong during program execution—that something could potentially cause a program to abort. One such situation would be trying to access a nonexistent object, as in the following example:
Student s1 = new Student(); Student s2 = null; s1.Name = "Fred"; // this line is fine s2.Name = "Mary"; // this line throws an exception
Let's explore what is happening in the preceding code.
We declare two Student object references but only instantiate one Student object; s2 is assigned the value null, indicating that it isn't presently holding onto any object.
Student s1 = new Student(); Student s2 = null;
When we subsequently attempt to assign a value to ...
Read now
Unlock full access