try catch捕获到的exception怎么转为string呢

try catch捕获到的exception怎么转为string呢?直接用string强转出来是string pair类型,没办法当成string处理,我需要对exception进行strReplace。

例如,执行下面语句:

try{ 
	1\`7 
} catch(ex){
	print(ex)
	print(typestr(ex))
	print( typestr(string(ex)))
}

输出:

"SYSTEM_Operator" : "Both arguments for ratio must be numbers."
STRING PAIR
STRING PAIR
请先 登录 后评论

1 个回答

Yating Xie

对于pair类型的数据,可以用下标0、1取到对应的值。比如以下脚本中,用ex[1] ,可以取到pair的第二个值,类型是string

try {1/`7} 
catch(ex){
	print (ex)
	print (ex[0])
	print (ex[0]+ex[1])
	print (typestr(ex[0]+ex[1]))
	print(typestr(ex))
}

attachments-2022-11-vE2qoeUt6360c5ba11c9b.png

请先 登录 后评论
  • 1 关注
  • 0 收藏,776 浏览
  • BMO 提出于 2022-11-01 15:06