Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Throwing Exceptions Exercise

Hi, I a dyslexic who is completely new to C#, and I honestly don't understand what I'm expected to do here or even how I'm supposed to do it - I would appreciate someone breaking down for me further what and how I'm supposed to do this exercise or maybe provide some kind of one-on-one Tutoring links that I could use - Thank you...

Steven Parker
Steven Parker
231,008 Points

It would be most helpful if you supply a link to the course page you are asking about.

The only "one-on-one Tutoring" available that I am aware of is the mentoring part of the Techdegree programs.

Sorry, here's the link to the exercise I'm working on: https://teamtreehouse.com/library/c-objects/inheritance/throwing-exceptions-2

1 Answer

Katrin Nitsche
Katrin Nitsche
23,462 Points

You have to do 2 things.

  1. You check if the value is between 0 and 20.
  2. If the value is is less than 0 or above 20 than throw an exception, because those values are not correct.

Exceptions are used to tell if something is going wrong. This can happen automatically, e.g. a file doesn't exists and you want to read it or in cases when the programmer decides something is wrong, e.g. a variable has the wrong value or an input is missing.

In the case of the exercise you need this. I usually write pseudo code

// check if the value is below 0 or above 20

if (.. C# code to check "value" variable ...) {

// then ... throw an exception with the text "The value is outside of the range. 0 to 20."

... C# code to throw a generic exception with a message text ...

}

You need to break down your task in little steps and first try to write you "code" in English. Than you can fill the gabs with C# code. I hope this helps.

I'll try it - Not sure if I fully understand, but I'll try - Thank you, Katrin...

Amil