Evaluate the object supplied to raise

A Python inventory checker calls reject_order to signal a rejected request. Its helper either constructs a shortage exception or raises an exception about invalid stock data. All quantities are integer item counts.


Python
def make_problem(units, stock):
    if stock < 0:
        raise ValueError("Stock must be nonnegative")
    return ValueError(f"Shortfall: {units - stock} items")

def reject_order(units, stock):
    raise make_problem(units, stock)


For each independent call, enter the exact exception message without quotation marks. Also enter the name of the function that directly raises the reported exception: make_problem or reject_order. Constructing or returning an exception object does not count as raising it.

CallException messageFunction directly raising the exception
reject_order(17, 9)
reject_order(12, -3)
reject_order(22, 15)

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Raising Exceptions Questions: