Not clear about the "Checked exception" explanation in "functional programming in Scala" -


in book of "functional programming in scala", there words talk "checked exception":

checked exceptions

java’s checked exceptions @ least force decision whether handle or reraise error, result in significant boilerplate callers. more importantly, don’t work higher-order functions, can’t possibly aware of specific exceptions raised arguments. example, consider map function defined list:

def map[a,b](l: list[a])(f: => b): list[b]

this function useful, highly generic, , @ odds use of checked exceptions — can’t have version of map every single checked exception possibly thrown f. if wanted this, how map know exceptions possible? why generic code, in java, resorts using runtimeexception or common checked exception type.

i read section several times, still not clear why checked exception not working higher-order functions.

could give examples make more clear?

try write function map<a, b> in java. @ point you'll find needing call mapping function. mapping function anything , throw kind of exception likes. function map cannot include in signature possible exceptions mapper can throw because has no idea is. it's impossible write type signature of map checked exceptions.

suppose signature of map colletion<b> map<a, b>(function<a,b>, collection<a>). suppose call map(x -> throw new ioexception, lists.of(1,2,3)). since ioexception checked, should appear in signature of map until called map, had no idea could throw type of exception.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -