Scala中的else语句的例外
if ( option != "AB" || option != "BC"|| option != "CD") {
try {
var option = dbutils.widgets.get("option")
}
catch {
case e: Exception => println("The option shoud be following AB, BC or CD " + option)
}
}
我试图在Scala中使用异常
,但是,当我使用诸如
“ XY”或其他值之外的任何其他值之外的值时,小部件值并没有引发异常。
请有人可以让我知道我在这里做错了什么。谢谢
if ( option != "AB" || option != "BC"|| option != "CD") {
try {
var option = dbutils.widgets.get("option")
}
catch {
case e: Exception => println("The option shoud be following AB, BC or CD " + option)
}
}
I am trying to use exception in scala
However, the widget value is not throwing an exception when I use the value such as
"XY" or any other value than AB, BC or CD.
Please can someone let me know what I am doing wrong here. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果AB,BC& CD是有效的值,那么您的谓词应该看起来像这样:
另外,您可以使用
需要
函数来执行谓词并在输入不匹配时抛出异常:If AB,BC & CD are the valid values, then your predicate should look like this:
Also, you can use the
require
function to enforce the predicate and throw an exception if the input doesn't match: