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 Throwing Exceptions

Jose Perez
Jose Perez
1,338 Points

throwing exception is not fully understood? Please help.

I dont really understand how does the throw new System.Exception in the constructor in the MapLocation class interact with the catch when trying to create the Maplocation object.

What happens if there is no catch wont the throw exception in the constructor throw the exception that it MapLocation object being created is not on the map? Can someone please explain so I can better understand.

Thank you!

1 Answer

Steven Parker
Steven Parker
231,269 Points

When the exception is thrown, it causes the code in the "catch" block to start running. It doesn't matter that the "throw" happened in a different module.

If there is no "try" and "catch", then a "throw" will cause the entire program to stop and the system will print out an error message.