reporting error from function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • laxmanscdot
    New Member
    • Sep 2006
    • 2

    #1

    reporting error from function

    hi all,
    When the processing error is more than two, than which approach is better(as mentioned below):

    Say the error may be
    ERR_A
    ERR_B
    ERR_C
    ERR_D

    1) one approach could be function it self return the error code and it is the responsibility of caller to intialize the error.
    2) Another the function return either bool or void and the function itself set the error. As we do in the C for example in the case of file open

    please suggest pros and cons..
    Laxman Singh
  • pukur123
    New Member
    • Sep 2006
    • 61

    #2
    I don't know whether you are talking about standard APIs or user defined functions.

    In case of standard APIs, if the API fails, the API will set corresponding the error values (if any defined in the manual page for that API) to the variable "errno" which is defined in the header file error.h.

    In case of user defined functions, we can not return more than one value. So if we expecting four error values and one return value from a function, we have to pass the reference of four local variables to the function as arguments.

    Comment

    • laxmanscdot
      New Member
      • Sep 2006
      • 2

      #3
      Originally posted by pukur123
      I don't know whether you are talking about standard APIs or user defined functions.

      In case of standard APIs, if the API fails, the API will set corresponding the error values (if any defined in the manual page for that API) to the variable "errno" which is defined in the header file error.h.

      In case of user defined functions, we can not return more than one value. So if we expecting four error values and one return value from a function, we have to pass the reference of four local variables to the function as arguments.

      **
      As approach is concern how it is differ for standard API and user defined function. In user defined function also you can use unique error codes(declared one of the header file) and those error code could be return or set to some global variable (say cn_error).

      why can i not return more than one value from user defined function ? Because if my return type is 'unsigned char' then i could able to return multiple error codes by simply returning (i.e. return ERR_A).

      please suggest some pros and cons.

      Laxman Singh

      Comment

      Working...