在Google表格自定义功能中投放自定义例外和错误消息? [英] Throwing custom exceptions and error messages in Google Sheets custom function?

查看:107
本文介绍了在Google表格自定义功能中投放自定义例外和错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google表格中(如Excel等),如果用户在公式中输入错误的输入,将在违规单元中打印错误代码,并且小弹出窗口提供有关错误的更多详细信息。因此,如果我输入'= SQRT(-1)',单元格中会打印'#NUM!',并且弹出窗口会解释该值需要等于或大于0。

In Google Sheets (as with Excel, etc) if a user enters bad input into a formula, an error code will be printed in the offending cell and a small pop-up provides more detail about the error. So if I enter '=SQRT(-1)', '#NUM!' is printed in the cell and the pop-up explains that the value needs to be equal to or greater than 0.

如何使用Google表格中的自定义功能复制此内容?抛出一个异常大多是有效的。例如,如果我捕捉到一个超出界限的输入值,然后抛出一个自定义异常,#ERROR!被打印在违规的单元格中(这很好),并且在相应的弹出窗口中打印了异常的伴随字符串(这也很好)。问题在于Google Apps脚本引擎还会将异常消息附加到生成异常的相应源代码行。因此,读取输入值必须介于0.0和1.0之间的弹出式菜单而不是弹出式菜单,它将显示输入值必须介于0.0和1.0之间(第199行)。

How can I replicate this with a custom function in Google Sheets? Throwing an exception mostly works. For example, if I catch an out-of-bounds input value and then throw a custom exception, "#ERROR!" is printed in the offending cell (which is fine) and the exception's accompanying string is printed in the corresponding pop-up (which is also fine). The problem is that the Google Apps Script engine also appends to the exception message the corresponding source code line that generated the exception. So instead of the pop-up simply reading "The input value must be between 0.0 and 1.0", it will read "The input value must be between 0.0 and 1.0 (line 199)".

是否有任何方法可以禁止打印行号或覆盖弹出消息?我希望能够抛出自定义错误并为我的用户提供详细的错误消息。但我不希望他们被一个与他们无关的行号引用混淆。

Is there any way to suppress the printing of the line number, or to overwrite the pop-up's message? I want to be able to throw custom errors and provide detailed error messages for my users. But I don't want them to be confused by a reference to a line number that is irrelevant to them.

推荐答案

这是报告的问题。

访问 Issue 4422 ,为它投票并更新。

Visit Issue 4422, star it to vote and for updates.

这篇关于在Google表格自定义功能中投放自定义例外和错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆