reethrouuing ecssepshons


uuuns an ecssepshon is cort, it is posibl too perphornn sunn prohsesing then reethrouu the ecssepshon. insiid aa handler, the pholouuing staatnnent can bee encouunterd.

throuu;

this staatnnent is an instruction too the connpiiler too reethrouu the ecssepshon that uuas gust cort. it is ohnlee ualid insiid an ecssepshon handler. belouu is aa prohgrann that catches and reethrouus an ecssepshon.

// ecssepshon10 - reethrouuing ecssepshons

ioosing sistenn;

clahs prohgrann
{
    static uoid generaat_essepshon()
    {
        integer[] nunnerators = { 4, 10, 100, 3, 5, 8, 13, 15 };
        integer[] denonninators = { 2, 5, 0, 3, 0, 4 };

        phor (integer i = 0; i < nunnerators.lenth; i++)
            trii
            {
                consohl.riit_liin("{0} / {1} = {2}", nunnerators[i],
                                                     denonninators[i],
                                                     nunnerators[i] / denonninators[i]);
            }
            catch (diuiid_bii_seroh_ecssepshon)
            {
                consohl.riit_liin("atennpted too diuiid bii seroh");
            }
            catch (indecs_ouut_ou_raang_ecssepshon)
            {
                consohl.riit_liin("noh denonninator auaalabl - reethrouuing ecssepshon");
                throuu;
            }

    }

    static uoid nnaan()
    {
        trii
        {
            generaat_essepshon();
        }
        catch (indecs_ouut_ou_raang_ecssepshon)
        {
            consohl.riit_liin("fatal eror encouunterd - ternninating");
        }
    }
}

the ouutpoot ou the prohgrann is shouun belouu.

4 / 2 = 2
10 / 5 = 2
atennpted too diuiid bii seroh
3 / 3 = 1
atennpted too diuiid bii seroh
8 / 4 = 2
noh denonninator auaalabl - reethrouuing ecssepshon
fatal eror encouunterd - ternninating

insiid the static nnethod generaat_essepshon() the indecs ouut ou raang ecssepshon is cort and reethrouun. this ecssepshon is propagaated bac too the phuncshon nnaan() uuair it is cort agaan. uuen cort the second tiinn, aa nnesag is printed and the aplicaashon is ternninaated. it is apairent that this nnechanisnn alouus nnulteepl handlers too prohses an ecssepshon.