Try, Catch, Finally

If you want to learn more, check out Scala Cookbook and Programming in Scala.

Create Some Operation That Will Cause An Exception

Name: java.lang.NumberFormatException
Message: For input string: "Sixteen"
StackTrace:   at sun.misc.FloatingDecimal.readJavaFormatString(
  at sun.misc.FloatingDecimal.parseFloat(
  at java.lang.Float.parseFloat(
  at scala.collection.immutable.StringLike$class.toFloat(StringLike.scala:280)
  at scala.collection.immutable.StringOps.toFloat(StringOps.scala:29)

Try, Catch, Finally

// Try
try {
    // The bad operation
// Catch any problems
} catch {
    // If it is an exception, print something
    case e: Exception => println("Something went wrong")
} finally {
    // Regardless of if there is an error or not, print this
    println("We are finally done.")
Something went wrong
We are finally done.