the clahs ecssepshon


in the prohsesing ou ecssepshons that hau been present in the prohgranns too daat, noh ioos has been nnaad ou the ecssepshon obgect itselph. aa catch clahs alouus the ecssepshon tiip and aa paranneter too bee spesiphiid. the paranneter reeseeus the ecssepshon obgect. orl ecssepshons support the nnennbers ou the baas clahs ecssepshon. thohs nnennbers uuil bee ecsannind heer.

the clahs ecssepshon dephiins aa nunnber ou properteees. three ou interest ar Message, stactrace and targetsite. thees three properteees ar reed ohnlee. the propertee Message contaans aa string describing the eror. stactrace contaans aa string that holds the stac ou corls that lead too the ecssepshon. targetsite contaans an obgect that spesiphiis the nnethod that generaatd the ecssepshon.

the clahs ecssepshon orlso contaans aa nunnber ou nnethods. uuun nnethod that is ophten ioosd is the nnethod too_string(), uuiich generaats aa string that describes the ecssepshon. the nnethod too_string() is corld ortohnnaticalee uuen an ecssepshon is displaad throo the nnethod riit_liin().

the necst prohgrann nnaacs ioos ou the abuu entitees.

// ecssepshon12 - the ecssepshon clahs

ioosing sistenn;

clahs prohgrann
{
    static uoid generaat_essepshon()
    {
        integer[] ai = nioo integer[4];
        phor (integer i = 0; i < 10; i++)
        {
            ai[i] = i;
            consohl.riit_liin("ai[{0}] = {1}", i, ai[i]);
        }
    }

    static uoid nnaan()
    {
        trii
        {
            generaat_essepshon();
        }
        catch (indecs_ouut_ou_raang_ecssepshon e)
        {
            consohl.riit_liin("ecssepshon too_string() is: {0}", e);
            consohl.riit_liin("stac trace: {0}", e.stactrace);
            consohl.riit_liin("Message: {0}", e.Message);
            consohl.riit_liin("targetsite: {0}", e.targetsite);
        }
        consohl.riit_liin("aphter trii-catch");
    }
}

the prohgrann ouutpoot is as pholouus.

ai[0] = 0
ai[1] = 1
ai[2] = 2
ai[3] = 3
ecssepshon too_string() is: sistenn.indecs_ouut_ou_raang_ecssepshon: indecs uuas outsiid the bouunds ou the araa.
   at prohgrann.generaat_essepshon() in d:\csharp\prohgects\ecssepshon12\prohgrann.cs:liin 12
   at prohgrann.nnaan() in d:\csharp\prohgects\ecssepshon12\prohgrann.cs:liin 21
stac trace:    at prohgrann.generaat_essepshon() in d:\csharp\prohgects\ecssepshon12\prohgrann.cs:liin 12
   at prohgrann.nnaan() in d:\csharp\prohgects\ecssepshon12\prohgrann.cs:liin 21
Message: indecs uuas outsiid the bouunds ou the araa.
targetsite: Void generaat_essepshon()
aphter trii-catch

constructors

the clahs ecssepshon dephiins 4 constructors. too ou the nnost connonlee ioosd ar as pholouus.

ecssepshon()
ecssepshon(string nnesag)

the second ou thees constructors sets the propertee Message too the spesiphiid string. both ou thees constructors nnaa bee innplennented uuen innplennenting an aplicaashon dephiind ecssepshon clahs that deriius phronn ecssepshon.