Класс: testCase
Пакет: matlab.mock
Выдать исключение для вызова метода или взаимодействия свойств
throwExceptionWhen(testcase,behavior)
throwExceptionWhen(testcase,behavior,exception)
throwExceptionWhen( указывает, что макет должен выдавать исключение, когда вызывается метод или свойство получено или задано.testcase,behavior)
throwExceptionWhen( задает исключение, которое выдает макет.testcase,behavior,exception)
Использование throwExceptionWhen метод функционально эквивалентен использованию matlab.mock.actions.ThrowException действие со when метод MethodCallBehavior, PropertyGetBehavior, или PropertySetBehavior класс. Например, следующие блоки кода функционально эквивалентны.
% Using the throwExceptionWhen method testCase.throwExceptionWhen(behavior.deposit(IsLessThan(0)), ... MException('Account:deposit:Negative', ... 'Deposit amount must be positive.')); % Using the ThrowException action with the when function import matlab.mock.actions.ThrowException when(behavior.deposit(IsLessThan(0)),ThrowException( ... MException('Account:deposit:Negative', ... 'Deposit amount must be positive.')))
ThrowException действие. Например, вы можете задать различное последующее поведение для того же взаимодействия заданных объектов.