Lecture overview -- Keyboard shortcut: 'u'  Previous page: Propagering af exceptions (2) -- Keyboard shortcut: 'p'  Next page: Finally i forhold til return, break og continue -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Play sound for this page -- Keyboard shortcut: 'y'  Page 19 : 26
Forelæsningsnoter i Objekt-orienteret Programmering
Undtagelseshåndtering
Finally i Java's try blok (1)

I forlængelse af ovenstående behandling af try catch er det naturligt at introducere finally konstruktionen. En finally konstruktion bliver udført uanset hvilken vej man vælger ud af en try

Finally konstruktionen i forlængelsen af try-catch muliggør en samlet afslutning af normaltilfældet og undtagelsestilfældet i Java


try{
 kommando-liste-0
}
catch (exception-klasse-1 formel-parameter-1){
 kommando-liste-1
}
catch (exception-klasse-2 formel-parameter-2){
 kommando-liste-2
}
...
finally{
 kommando-liste-3
}

Syntaks for try kommandoen i Java med en finally del.