SlideServe
Menu
Préférences
© SlideServe · v2026

Error Handling in C

rance avatar
8 diapositives · 1.4K Views · Jul 10, 2014

Error Handling in C. Errors - An unpleasant way. Errors – Graceful degradation of service. Error Handling. There are always some errors in programs/software It’s a programmers job to anticipate errors And make the program to handle errors gracefully.

Error Handling in C - slide 1
01 / 8Error Handling in C
1 / 17

Télécharger la présentation

Error Handling in C
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Error Handling in C

  2. Errors - An unpleasant way

  3. Errors – Graceful degradation of service

  4. Error Handling • There are always some errors in programs/software • It’s a programmers job to anticipate errors • And make the program to handle errors gracefully. • Users cannot understand technical jargons • A message from the program must inform the user that something unexpected occurred • Which will be taken care of in due course of time

  5. Error Handling in C • Modern programming languages provide support for error handling (sometimes called exception handling) • C however, provides limited error handling in the form of returned values • Most of the times, if a function returns NULL or the value -1, it means that an error has occurred • In DevC++, error codes defined for various operations are defined in errno.h

  6. Error Handling in C • We have already implemented (in one of the ways) the capability of handling errors in our programs • Remember…??? if (inputfp == NULL) { printf("Can't open input file my_input.txt!\n"); system("pause"); return 0; } • Lets try another way of handling similar errors

  7. Error Handling in C • The function perror() prints out the string strfollowed by the actual string equivalent of the error that had occurred if (inputfp== NULL) { perror("Error printed by perror"); } • The output of this code segment would be: Error printed by perror : No such file or directory

  8. Error Handling in C • We can make similar arrangements for other errors such as: • Divide by zero • Unsuccessful memory allocation operation with malloc().