joshua-r2
11/7/2017 - 2:39 PM

Simple Try-Catch-Finally

Used to handle code safely, especially when opening a file


fun readAFile(reader: BufferedReader): Int?
{

  try{
    val line = reader.readline
    return line.toString()
  }
  catch(e : StringFormatException){
    return null
  }
  finally{
  //Cleanup
    reader.close()
  }
}