How can I catch exceptions from external processes that are combined with #&& etc.. ?
scala> import scala.sys.process._
scala> try{ "throw " ! }catch{ case e: Exception => }
res1: AnyVal = ()
scala> try{ "throw " #&& "ls" ! }catch{ case e: Exception => }
Exception in thread "Thread-10" java.io.IOException: Cannot run program "throw": error=2, No such file or directory
You already do. Try
try {
val x = "throw" #&& "ls" !
} catch {
case x => println("caught")
}
The !
just logs the exception to the console, which is a bit confusing when you see it in the REPL, but it does not crash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With