Dispose() és finlaize() összefogása egyszerűen

Filed Under (Uncategorized) by nameless on 02-08-2009

Gyakran alkalmazunk strukturál kivételkezelést annak biztosítására, hogy a rendszer futásidejű hiba esetén a Dispose() metódust hívja:

 
            using (var myDispos = new MyResourceWrapper())
            {
                //myDispos objektumok használata
            }

ez a kód igazából csinál egy try/finally blokkot, hogy mindenképp meg legyen hívva a Dispose() metódus. (természetesen azt is meghívja)

Finally blokk

Filed Under (Uncategorized) by nameless on 02-08-2009

Read the rest of this entry »

A finalize felülbírálása

Filed Under (Uncategorized) by nameless on 02-08-2009

Read the rest of this entry »

Szemétgyűjtés kényszerítés

Filed Under (Uncategorized) by nameless on 02-08-2009

Read the rest of this entry »

Egyedi kivételkezelés 3.

Filed Under (Uncategorized) by nameless on 02-08-2009

Read the rest of this entry »

Egyedi kivételkezelés 2.

Filed Under (Uncategorized) by nameless on 02-08-2009

Ebben az esetben nem definiálunk sztringváltozót, hanem csak átadunk paramétert az ős konstruktorának. Így az egyedi kivétel nem lesz egyedi, viszont a megnevezése az lesz . A szerepe egy erősen megnevezett típus biztosítása, amely egyértelműen azonosítja a hiba természetét.

CarIsDead osztály:

public class CarIsDeadException : ApplicationException
 {
      private DateTime errorTimeStamp;
      private string causeOfError;
 
      public DateTime TimeStamp
      {
         get { return errorTimeStamp; }
         set { errorTimeStamp = value; }
      }
      public string Cause
      {
         get { return causeOfError; }
         set { causeOfError = value; }
      }
 
      public CarIsDeadException() { }
 
      Feed message to parent constructor.
      public CarIsDeadException(string message,
      string cause, DateTime time)
        : base(message)
      {
         causeOfError = cause;
         errorTimeStamp = time;
      }
 }

Egyedi kivételkezelés 1.

Filed Under (kód) by nameless on 02-08-2009

Ez a forráskód úgy van megoldva, hogy több .cs fájl foglal magába. Project -> Add new Item -> Class
Egyedi kivételkezelés 1.
Read the rest of this entry »

Belső kivétel

Filed Under (Uncategorized) by nameless on 02-08-2009

Read the rest of this entry »

Kivétel továbbdobása:

Filed Under (kód) by nameless on 02-08-2009

Tagged Under :

Read the rest of this entry »

Többszörös kivétel fogadás

Filed Under (kód) by nameless on 02-08-2009

Többszörös kivétel fogadás
Read the rest of this entry »