Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why intercept command is not not working on scala 2.11.7

Tags:

scala

i am doing some scala exercises using the resources from scala Exercises and i have found that intecept command is not working.

MacBook-Pro-Retina-de-Alonso:~ aironman$ scala
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val myMap = Map("OH" -> "Ohio", "WI" -> "Wisconsin", "IA" -> "Iowa")
myMap: scala.collection.immutable.Map[String,String] = Map(OH -> Ohio, WI -> Wisconsin, IA -> Iowa)

scala> var blewWithException = true
blewWithException: Boolean = true

scala> intercept[NoSuchElementException] {
 |   myMap("MI")
 |   blewWithException = false
 | }
 <console>:13: error: not found: value intercept
   intercept[NoSuchElementException] {
   ^

 scala>

My excuses if this question is already solved, but the system is not retrieving me the solution.

like image 792
aironman Avatar asked Dec 05 '25 03:12

aironman


1 Answers

intercept method is a part of a test library, you have to download ScalaTest jar and extend Assertions trait to use it.

like image 147
ka4eli Avatar answered Dec 06 '25 19:12

ka4eli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!