Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process composition and exceptions

Tags:

scala

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
like image 386
Ido Tamir Avatar asked Sep 03 '12 09:09

Ido Tamir


1 Answers

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.

like image 173
drexin Avatar answered Sep 24 '22 13:09

drexin