G. H. RAISONI COLLEGE OF ENGG. & MANAGEMENT Gat No. 1200, Wagholi, Pune – 412 207 (An Autonomous Institute Affiliated to Savitribai Phule Pune University) Session 2020-21 Presentation on ERROR HANDLING IN C PROGRAMMING By Panali Ravindra Patil (A43) Faculty Name: Ms Mugdha Kirkire . FY B.Tech: Div A
Content : • What is a C language ? • Why we use C language? • Facts about C. • Errors in C. • Types of errors in C language . • Types of error handling in C language . 2
3
What is a C language ? • C is a general-purpose programming language that is extremely popular, simple, and flexible to use. • It is a structured programming language that is machine-independent and extensively used to write various applications, Operating Systems like Windows, and many other complex programs like Oracle database, Git, Python interpreter, and more. • It is said that 'C' is a god's programming language. One can say, C is a base for the programming. • If you know 'C,' you can easily grasp the knowledge of the other programming languages that uses the concept of 'C' • It is essential to have a background in computer memory mechanisms because it is an important aspect when dealing with the C programming language 4
Why we use C language ? • C was initially used for system development work, in particular the programs that make-up the operating system. • C was adoped as a system development language because it produces code that runs nearly as fast as code written in assembly language. • Some examples of the use of C might be: • Operating System •Language Compilers • Assemblers • Text Editors All the C programs are writen into text files with extension ".c" for example hello.c. 5
Facts about c language • Easy to learn • Structured language • It produces efficient programs. • It can handle low-level activities. • It can be compiled on a variety of computers. • The language was formalized in 1988 by ANSI. 6
Errors When we compile any C -program sometimes it give us a Bug or an Error. Program errors are also referred to as program bugs. Errors in C : • As such C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values. • Most of the C or even Unix function calls return -1 or NULL in case of any error and sets an error code errno is set which is global variable and indicates an error occurred during any function call. • You can find various error codes defined in header file. So a C programmer can check the returned values and can take appropriate action depending on the return value. • As a good practice, developer should set errno to 0 at the time of initialization of the program. A value of 0 indicates that there is no error in the program 7
Types of errors in C language A C program may have one or more of four types of errors: • Syntax errors (Compiler errors or Compile- time errors) • Linker Errors • Runtime errors • Logic errors Usually, the errors become more difficult to find and fix. 8
Syntax error : • The set of rules (grammatical rules) of a programming language for writing statements of the computer program is known as syntax of the language. • The program statements are written strictly according to these rules. Syntax error occur when syntax of a programming language are not followed in writing the source code. • The compiler detects these errors at compiling time of source code. • The compiler reports a proper error message about the error. The compiler does not compile a program that contain syntax errors.The syntax errors are easy to detect and remove. 9
Linker errors • Linker errors are generated when the linker encounters what looks like a function call; but it cannot find a function with that name. • This is usually caused by misspelling a C standard function (like main) or not including the header file for a function. • Examples 1. • Misspelling a standard C function: • Examples 2. • Not including the header file for a function: • Dev C++ has an option that automatically includes standard header files. It is not recommended to use this option, as it is CPU-intensive. • To turn off this option use the menus: • Tools Compiler Options Settings Linker and set "Do not use standard system startup files or libraries" to Yes: • With the option turned off, not including a standard header file in your program will generate a linker error 10
Types of error handling in C language • errno • perror • strerror • The C programming language provides perror and strerror functions which can be used to display the text message associated with errno. • The perror function displays the string you pass to it, followed by a colon, a space, and then the textual representation of the current errno value. • The strerror function, which returns a pointer to the textual representation of the current errno value. 11
12

Error hanadling in c programming presentation

  • 1.
    G. H. RAISONICOLLEGE OF ENGG. & MANAGEMENT Gat No. 1200, Wagholi, Pune – 412 207 (An Autonomous Institute Affiliated to Savitribai Phule Pune University) Session 2020-21 Presentation on ERROR HANDLING IN C PROGRAMMING By Panali Ravindra Patil (A43) Faculty Name: Ms Mugdha Kirkire . FY B.Tech: Div A
  • 2.
    Content : • Whatis a C language ? • Why we use C language? • Facts about C. • Errors in C. • Types of errors in C language . • Types of error handling in C language . 2
  • 3.
  • 4.
    What is aC language ? • C is a general-purpose programming language that is extremely popular, simple, and flexible to use. • It is a structured programming language that is machine-independent and extensively used to write various applications, Operating Systems like Windows, and many other complex programs like Oracle database, Git, Python interpreter, and more. • It is said that 'C' is a god's programming language. One can say, C is a base for the programming. • If you know 'C,' you can easily grasp the knowledge of the other programming languages that uses the concept of 'C' • It is essential to have a background in computer memory mechanisms because it is an important aspect when dealing with the C programming language 4
  • 5.
    Why we useC language ? • C was initially used for system development work, in particular the programs that make-up the operating system. • C was adoped as a system development language because it produces code that runs nearly as fast as code written in assembly language. • Some examples of the use of C might be: • Operating System •Language Compilers • Assemblers • Text Editors All the C programs are writen into text files with extension ".c" for example hello.c. 5
  • 6.
    Facts about clanguage • Easy to learn • Structured language • It produces efficient programs. • It can handle low-level activities. • It can be compiled on a variety of computers. • The language was formalized in 1988 by ANSI. 6
  • 7.
    Errors When we compileany C -program sometimes it give us a Bug or an Error. Program errors are also referred to as program bugs. Errors in C : • As such C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values. • Most of the C or even Unix function calls return -1 or NULL in case of any error and sets an error code errno is set which is global variable and indicates an error occurred during any function call. • You can find various error codes defined in header file. So a C programmer can check the returned values and can take appropriate action depending on the return value. • As a good practice, developer should set errno to 0 at the time of initialization of the program. A value of 0 indicates that there is no error in the program 7
  • 8.
    Types of errorsin C language A C program may have one or more of four types of errors: • Syntax errors (Compiler errors or Compile- time errors) • Linker Errors • Runtime errors • Logic errors Usually, the errors become more difficult to find and fix. 8
  • 9.
    Syntax error : •The set of rules (grammatical rules) of a programming language for writing statements of the computer program is known as syntax of the language. • The program statements are written strictly according to these rules. Syntax error occur when syntax of a programming language are not followed in writing the source code. • The compiler detects these errors at compiling time of source code. • The compiler reports a proper error message about the error. The compiler does not compile a program that contain syntax errors.The syntax errors are easy to detect and remove. 9
  • 10.
    Linker errors • Linkererrors are generated when the linker encounters what looks like a function call; but it cannot find a function with that name. • This is usually caused by misspelling a C standard function (like main) or not including the header file for a function. • Examples 1. • Misspelling a standard C function: • Examples 2. • Not including the header file for a function: • Dev C++ has an option that automatically includes standard header files. It is not recommended to use this option, as it is CPU-intensive. • To turn off this option use the menus: • Tools Compiler Options Settings Linker and set "Do not use standard system startup files or libraries" to Yes: • With the option turned off, not including a standard header file in your program will generate a linker error 10
  • 11.
    Types of errorhandling in C language • errno • perror • strerror • The C programming language provides perror and strerror functions which can be used to display the text message associated with errno. • The perror function displays the string you pass to it, followed by a colon, a space, and then the textual representation of the current errno value. • The strerror function, which returns a pointer to the textual representation of the current errno value. 11
  • 12.