Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,017 Points

the correct answer is

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

}
}