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#

Why does the constructor in the class not contain a void function? Or any data type for that matter?

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

}

For example, in this case, the function does not have a data type. I understand that it is not returning something and that the base class constructor is returning an Exception Object but shouldn't this be a void?

1 Answer

Steven Parker
Steven Parker
229,786 Points

Constructors are special in this way. As described on the MDN documentation page for constructors:

Its method signature includes only the method name and its parameter list; it does not include a return type.

Makes sense because a constructor is defined by the class it is in. Thanks for the help!