Scala try and catch Error -
so here code:
def loadoperation(filename:string): csvlist = { try{ val pattern = """^(.+);(\d{5});(4|2|31);(0|1);(.+);(\d+|\d+,\d+)$""".r source.fromfile(filename).getlines().foldleft(list[csventry]())((csvlist, currentline) => currentline match { case pattern(organisation,yearandquartal,medkf,trueorfalse,name,money) => new csventry(organisation,yearandquartal.toint,medkf.toint,trueorfalse.toint,name,money) :: csvlist case default => csvlist }) } catch { case one: java.io.filenotfoundexception => println("this file not found!") }}
the problem code doesnt work, shows following error:
type mismatch found: unit required csvlist expands list[csventry]?
how can solve problem?
the problem catch
clause:
println("this file not found!")
has type unit
, not csvlist
. should add additional line returns empty list, such as
catch { case one: java.io.filenotfoundexception => println("this file not found!") } nil
Comments
Post a Comment