Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Inheritance in C#!
You have completed Practice Inheritance in C#!
In this video, we'll review the solution to the third challenge and introduce our fourth and final challenge—throwing and catching exceptions.
Instructions
4th Challenge
-
In the MediaType.cs file...
- Throw an exception in the MediaType class constructor if the
title
parameter is set tonull
or an empty string. - Set the exception's message to "A media type must have a title."
- Throw an exception in the MediaType class constructor if the
-
In the Program.cs file...
- Throw an exception in the
DetectMediaType()
helper method when an unexpected media subtype is encountered. - Set the exception's message to "Unexpected media subtype encountered."
- Wrap the code in the
Main()
method in atry/catch
statement. - Define a parameter in the
catch
clause in order to get a reference to the caught exception. - Write the exception's
Message
property to the console.
- Throw an exception in the
Help
If you get stuck on any of the following topics or simply need a refresher, click on a topic in list below to view the associated video in the C# Objects course.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up