Can you replace this with a Scala `Try` block to make it less Java-like?