请教 MException 的对象函数为何不能用 "对象名.方法" 的形式?。
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
果博东方开户注册【微8785092】
el 23 de Mayo de 2023
Respondida: 果博东方开户咨询【微8785092】
el 23 de Mayo de 2023
我用的是matlab R2020a,根据函数参考手册,MException的对象函数有 addCause、throw等。
我以 addCause 来说明我的问题。下面这个例子来自于 addCause 的函数参考
1 A = [13 42; 7 20];
2 idx = [1 0 1; 0 1 0];
3 try
4 A(idx);
5 catch
6 errID = 'MYFUN:BadIndex';
7 msg = 'Unable to index into array.';
8 baseException = MException(errID,msg);
9 try
10 assert(islogical(idx),'MYFUN:notLogical',...
11 'Indexing array is not logical.')
12 catch causeException
13 baseException=addCause(baseException,causeException)
14 % baseException.addCause(causeException)
15 end
16 throw(baseException)
17 end
程序第13行,能正确地将对象 causeException 添加到 baseException中,
我认为 addCause 是 baseException 的对象函数,那就应该可以用第14行的语句实现同样功能
但第14行运行后,baseException的cause属性还是为空白。
请问这是为什么?baseException对象为什么不能用对象方法addCause?
谢谢!
0 comentarios
Respuesta aceptada
果博东方开户咨询【微8785092】
el 23 de Mayo de 2023
14行换成:
baseException = baseException.addCause(causeException)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Exception Handling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!