C

Error handling patterns in C

Në shqip: Trajtimi i gabimeve në C

ShpjegimiSQ

C-ja s'ka përjashtime. Funksionet zakonisht kthejnë një kod (0 = sukses, -1 ose NULL = gabim) dhe vendosin errno. Për të liruar burimet në një vend të vetëm, shpesh përdoret goto pastro;.

EnglishEN

C has no exceptions. Functions usually return a code (0 = success, -1 or NULL = error) and set errno. To free resources in one place, goto cleanup; is often used.

Si ta mendosh

Si raporti i shoferit: „0 — gjithçka mirë“ ose kodi i problemit.

Lexoje në anglisht

Like a driver's report: “0 — all fine” or the problem's code.

Shembull kodic

int lexo(const char *rruga) {
    FILE *f = fopen(rruga, "r");
    if (!f) return -1;
    /* ... */ fclose(f); return 0;
}

Terma të lidhur