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 trialmattcleary2
19,953 PointsSo when do we use Do and Catch statements?
Hey guys,
I'm a little confused.
At the end of the video, we write the functions for calculating the total price of the quantity of items selected and the errors in case the amount deposited is less than the total price.
With this we use throw statements, as obviously we're throwing errors such as insufficientFunds.
But why don't we then write all the Do and Catch stuff for the errors? Why are we moving on?
Any explanation would be very much appreciated. thank you.
1 Answer
akin
Courses Plus Student 2,865 PointsI think it is related to program design. It is called exception management. When something went wrong in runtime , another parts of the program can catch these errors and notify the user or can change program flow etc..And then program is not halted exceptionally. While you writing a program, everything may be true or correct but in runtime, somethings can produce unexpected results. In this time you can handle these logical errors or another strange situations with these way...
In C# , we are using try - catch code block for critical operations in methods or class.
akin
Courses Plus Student 2,865 Pointsakin
Courses Plus Student 2,865 PointsBy the way, you should learn OOP design techniques for best understanding these concepts...