Title: Try, Catch, Finally
Slug: try_catch_finally
Summary: Try, Catch, Finally Using Scala.
Date: 2017-01-03 12:00
Category: Scala
Tags: Basics
Authors: Chris Albon
If you want to learn more, check out Scala Cookbook and Programming in Scala.
In [19]:
"Sixteen".toFloat
Out[19]:
In [21]:
// Try
try {
// The bad operation
"Sixteen".toFloat
// 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.")
}
Out[21]: