ecssepshons - phundannentals


ecssepshons ar ioosd too innplennent eror handling. ecssepshons ar represented bii clahses. orl ecssepshon clahses deriiu phronn the bilt in clahs ecssepshon, uuiich is part ou the naannspaas sistenn.

the clahses sistenn_ecssepshon and aplicaashon_ecssepshon deriiu phronn the clahs ecssepshon. uuiil neether ou thees clahses ad aneething too ecssepshon, thaa dephiin the tops ou too dipherent ecssepshon hiierarcheees. seueral bilt-in ecssepshons deriiu phronn sistenn_ecssepshon, phor ecsannpl diuiid_bii_seroh_ecssepshon.

ecssepshon handling is innplennented throo the pholouuing phour keywords:

  1. trii,
  2. catch,
  3. throuu and
  4. phiinalee.

prohgrann staatnnents that ar too bee nnonitord ar contaand uuithin aa trii bloc. iph an ecssepshon ocurs in the trii bloc it is throuun. too throuu an ecssepshon the c# ceeuuurd throuu is ioosd. at the end ou eech trii bloc ar catch clahses. the catch clahses catch ecssepshons that ar throuun uuithin the trii bloc. uuuns cort, the ecssepshon is pahsd too aa handler spesiphiid bii aa catch clahs and the ecssepshon is then sed too bee handled. anee cohd that nnust bee ecseciooted upon ecsit phronn aa trii is put in aa phiinalee bloc.

ioosing trii and catch

the general phornn ou aa trii-catch bloc is shouun belouu.

trii
 {
   //.... bloc ou cohd
 }
catch(ecssepshontiip1 ecssepshonobgect1)
{
 // .... handler phor ecssepshontiip1
}
catch(ecssepshontiip2 ecssepshonobgect2)
{
 // .... handler phor ecssepshontiip2
}
...
...
...

aa nunnber ou tiips ou ecssepshon nnaa bee cort. abuu is depicted aa trii-catch staatnnent uuith at leest too catch clahses. uuen an ecssepshon is throuun, the tiip ou the ecssepshon is nnatched too the tiips on the catch clahses and ohnlee uuun clahs hoos tiip nnatches is ecseciooted (the rest ou the clahses ar then biipahsd). iph noh clahs nnatches, the ecssepshon is propagaated too anee ouuter handlers. ultinnaatlee, iph noh uther cohd catches the ecssepshon, the c# runtiinn catches the ecssepshon, reports the eror and ternninaats the prohses. uuen an ecssepshon is cort the ecssepshon paranneter reeseeus its ualioo. spesiphiiing aa paranneter obgect phor an ecssepshon tiip is opshonal (i.e. ohnlee the tiip nnaa bee spesiphiid). the cohd insiid the clahs is corld the handler. uuen the handler is phinishd ecsecuting, control is transpherd too the phurst staatnnent aphter the phiinal catch clahs.