Thread: Error Handling in C: Strategies and Implementations

  1. #1
    Registered User
    Join Date
    Oct 2022
    Posts
    96

    Error Handling in C: Strategies and Implementations

    I've noticed that C language lacks built-in support for try and catch mechanisms seen in other languages. How do you typically handle errors in C, and what strategies do you use to implement error handling akin to try and catch in your code?

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,128
    Quote Originally Posted by Kittu20 View Post
    I've noticed that C language lacks built-in support for try and catch mechanisms seen in other languages. How do you typically handle errors in C, and what strategies do you use to implement error handling akin to try and catch in your code?
    Many functions return some sort of error/success value that can be checked for success or failure. Those functions that return a regular value, can be checked, again if the value indicates success or failure.

    Check the man page for the Standard Library functions to see what they return, and other information regarding error checking.

    Your own functions could be written to return some value that can be checked.

    You can also use the assert macro, to abort the program if some condition fails.

    There are many articles that expand on this topic.
    Last edited by rstanley; 2 Weeks Ago at 06:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unrolling strategies
    By m37h0d in forum C++ Programming
    Replies: 14
    Last Post: 06-27-2011, 06:42 AM
  2. 5-in-a-row strategies
    By Elysia in forum General AI Programming
    Replies: 0
    Last Post: 07-28-2010, 11:23 AM
  3. Strategies for Handling Command Line Arguments
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 04-09-2008, 08:18 AM
  4. Automatic Testing Strategies
    By ichijoji in forum Game Programming
    Replies: 8
    Last Post: 04-25-2007, 11:45 AM

Tags for this Thread