CustomFunctions.Error class
使用此类来处理错误并编写自定义错误消息。
注解
[ API set: CustomFunctionsRuntime 1.2 ]
示例
/**
* Returns the #NUM! error as part of a 2-dimensional array.
* @customfunction
* @param {number} first First parameter.
* @param {number} second Second parameter.
* @param {number} third Third parameter.
* @returns {number[][]} Three results, as a 2-dimensional array.
*/
function returnInvalidNumberError(first, second, third) {
// Use the `CustomFunctions.Error` object to retrieve an invalid number error.
const error = new CustomFunctions.Error(
CustomFunctions.ErrorCode.invalidNumber, // Corresponds to the #NUM! error in the Excel UI.
);
// Enter logic that processes the first, second, and third input parameters.
// Imagine that the second calculation results in an invalid number error.
const firstResult = first;
const secondResult = error;
const thirdResult = third;
// Return the results of the first and third parameter calculations
// and a #NUM! error in place of the second result.
return [[firstResult], [secondResult], [thirdResult]];
};
构造函数
(constructor)(code, message) | 构造 类的新实例 |
属性
code | 自定义函数返回的错误代码。 |
message | 自定义错误消息,例如“此股票价格不可用”。 自定义消息仅适用于某些错误代码。 |
构造函数详细信息
(constructor)(code, message)
构造 类的新实例Error
constructor(code: ErrorCode, message?: string);
参数
- message
-
string
属性详细信息
code
自定义函数返回的错误代码。
code: ErrorCode;
属性值
注解
message
自定义错误消息,例如“此股票价格不可用”。 自定义消息仅适用于某些错误代码。
message?: string;
属性值
string