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# C# Objects Inheritance Custom Exceptions

Igor Kletsov
Igor Kletsov
7,556 Points

What wrong?

Challenge Task 2. Add a constructor to TooBigException that accepts a string for the exception message.

what is missing?

TooBigException.cs
namespace Treehouse.CodeChallenges
{
    class TooBigException: System.Exception
    {
       public TooBigException (string message)
       {

       }

    }

}

namespace Treehouse.CodeChallenges { class TooBigException : System.Exception { public TooBigException() {

    }
}

}

8 Answers

Jeremy McLain
STAFF
Jeremy McLain
Treehouse Guest Teacher

My apologies. I'm just now taking a look at this. This wasn't a compiler error. C# has very few requirements regarding spaces. The problem was in our test code.

Also, Igor is missing the call to the base constructor, so his code will still fail the challenge, but with a better error now.

This just passed the challenge:

namespace Treehouse.CodeChallenges
{
    class TooBigException: System.Exception{

        public TooBigException(string message) 
            : base(message)
        {

        } 
    }

}
Igor Kletsov
Igor Kletsov
7,556 Points

Your code works, my no. what is the difference ?

namespace Treehouse.CodeChallenges
{
    class TooBigException : System.Exception
    {
        public TooBigException (string message) : base (message)
        {

        }
    }
}

Do you see that space between TooBigException and your parameters? Try deleting that space, I bet that will fix it.

Igor Kletsov
Igor Kletsov
7,556 Points

Thank you, you're right. I spent two hours on it. I hate those bugs.

This worked for me!

namespace Treehouse.CodeChallenges { class TooBigException : System.Exception { public TooBigException() { } } }

public TooBigException(string message) 
            : base(message)
{

}

You're welcome, yeah those compilers can be picky sometimes.

namespace Treehouse.CodeChallenges { class TooBigException: System.Exception //Exception is in System namespace { } }

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points

the correct answer is

namespace Treehouse.CodeChallenges
{
class TooBigException : System.Exception
{

}
}