Join Gerry O'Brien for an in-depth discussion in this video Solution: Handle an error, part of Up and Running with C#.
In this particular challenge, we've asked…you to write structured exception handling.…And within your error handling, we've asked…you to catch the invalid cast exception.…A provided code will generate the invalid cast…exception, if you execute the application right now.…The reason being is the way we've done…the assignments of the values within this code.…We have created one variable that is of type…integer and we've stored a value of 32 in it.…We've also created an object variable called objValue.…Remember that all of our reference types…in C# ultimately inherit from the System.Object class.…So, object becomes a generic reference type.…Because all types ultimately inherit from System.Object, that means we can…also assign any values that we create in our application to an object type.…So, we're taking our integer value and we're assigning it to a new object value.…So, we're changing the type during this assignment.…We're changing it from an int to an object.…What Visual Studio does in the background is actually…
- Installing C#
- Working with loops
- Controlling program flow
- Using variables
- Building functions
- Creating and instantiating classes
- Catching errors
- Managing resources with the garbage collector
- Building collections
Skill Level Beginner
1. Introducing C#
2. C# Language Elements
3. Object-Oriented Programming in C#
4. Structured Exception Handling
5. Resource Management in C#
6. Extensible Types in C#
7. Windows Apps in C#
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.