this is implementation of Scala Try on Java