如果我下载这样的scala.sys.process
大文件:
import java.io.File
import java.net.URL
import scala.sys.process._
new URL("http://www.scala-lang.org/") #> new File("scala-lang.html") !
如果下载过程中出现问题,堆栈跟踪只会在stderr上打印,但不会在我的try-catch块中捕获。我相信有办法捕捉错误并重试,但我该怎么做?
答案 0 :(得分:1)
序列
new URL("http://www.scala-lang.org/") #> new File("scala-lang.html") !
评估为Int
,对应于操作的退出代码。
当它等于0时,结果成功,否则出错。
所以它可以按如下方式处理
val result = new URL(...)
if (result != 0) {
throw new MyCustomException("message") // or retry
}