Skip to content

Instantly share code, notes, and snippets.

@ozw-sei
Created August 12, 2013 03:50
Show Gist options
  • Select an option

  • Save ozw-sei/6208131 to your computer and use it in GitHub Desktop.

Select an option

Save ozw-sei/6208131 to your computer and use it in GitHub Desktop.
Calc.scala
object Calc{
def main(args: Array[String]) = {
val two = Calc.add(1,1)
val one = Calc.sub(2,1)
val six = Calc.mul(3,2)
val five = Calc.div(10,2)
val err = try{
Calc.div(10,0)
}
catch{
case _:java.lang.IllegalArgumentException => {
println("IllegalArgumentException")
new IllegalArgumentException
}
}
finally{
println("always called")
}
println("two = " + two)
println("one = " + one)
println("six = " + six)
println("five = " + five)
println("err = " + err)
}
def add(num1 : Int, num2 : Int) = num1 + num2
def sub(num1 : Int, num2 : Int) = num1 - num2
def mul(num1 : Int, num2 : Int) = num1 * num2
def div(num1 : Float, num2 : Float) = {
import java.lang.IllegalArgumentException
if(num2 == 0)
throw new IllegalArgumentException("devide by zero")
else
num1 / num2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment