Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created March 23, 2011 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kings13y/882367 to your computer and use it in GitHub Desktop.
Save kings13y/882367 to your computer and use it in GitHub Desktop.
Type pattern match example using Exceptions as the Types
import java.io.{FileReader,FileNotFoundException,IOException}
try {
val file = new FileReader("noSuchFile")
} catch {
case e: FileNotFoundException => println("File not found !")
// Handle missing file
case e: IOException => println("IO Exception !")
// Handle other I/O error
case e => e.printStackTrace()
} finally { // cleanup resources
println("Close any open resources (if not using the loan pattern ;-] )")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment