Exercise · Exceptions · lesson 9 of 9
Exercise: a custom exception
A warehouse has left items in stock, and a customer wants to take n. Complete the two classes in the stub.
OutOfStockExceptionis an exception derived fromException. Its constructorOutOfStockException(string message)passes the message toException, soMessagereturns exactly that string.Solutionhas the methodpublic static int Take(int left, int n). The method returns how many items will remain. Ifnis greater thanleft, it throwsOutOfStockExceptionwith a message like"Only 3 left.", where the number is the value ofleft.
Take(10, 3)→7Take(5, 5)→0Take(3, 5)→ throwsOutOfStockExceptionwith the message"Only 3 left."
Constraints: left and n are integers from 0 to 1000; n may be 0.
Do not add extra using directives unless the task says so explicitly.