Yeah, there are problems with doing it that way. I'd do something like:

typedef enum DeductionLineErrors {
        e_DL_NoError = 0,                                               // no 
err
        e_DL_LineNumberExistsError = 1,                 // blah
        e_DL_WTFError = 2                                               // blah 
blah!
} DeductionLineErrors;

typedef enum DeductionLineSequentErrors {
        e_DLS_NoError = 0,                                              // no 
err
        e_DLS_LineNumberExistsError = 1000,     // blah
        e_DLS_WTFError = 1001                                   // blah blah!
} DeductionLineSequentErrors;

In other words, type the enums (optional, but more readable and you can use the types in code) and more importantly, use unique enum names to help prevent confusion when returning the errors from your different classes or chunks of code. Even more importantly, don't overlap the values you're using, except for "no error". It makes it a lot easier to track down the source of an error if only one error has a value of 1001, for example. By the time that error gets propagated to your log or interface, you may have no other clue what the original problem was and which class or chunk of code it came from.

- d

On Mar 20, 2008, at 11:31 PM, K. Darcy Otto wrote:
I've been trying to add some human-readable error codes to my classes using enum, but have been running into some difficulties when I add a different enum of the same name to a different class. Here is what I have so far in my DeductionLine class (and I think it will suffice just to show the interface:

@interface DeductionLine : NSObject {

        Dependency *dependency;
        LineNumber *lineNumber;
        Formula *formula;
        Justification *justification;
        BOOL wfdl; // well-formed deduction line
        
        enum Error
        {
                noError = 0, // everything ok
                dependencyExistError = 1, // dependency does not exist
                lineNumberExistError = 2, // line number does not exist
                formulaFormError = 3,  // formula is not a wff
                justificationFormError = 4, // justification is not a wfj
justificationReferenceError = 5, // justification references lines greater or equal to lineNumber justificationMatchError = 6 // justification is $I, but main connective of formula does not correspond to $
        } errorCode;
        
}

Now, I know the =0, =1 is redundant, but I want it there for ease of reading, just in case the programmer wants to output errorCode to a log (which will result in an integer, which can then be looked up in the interface). This works fine in this class: I can write: "errorCode = noError;" or whatever, and everything is happy. But when I try to do something similar in the DeductionLineSequent class, there is no end to compiler complaining:

@interface DeductionLineSequent : NSObject {

        NSArray *sequent;
        NSArray *additionalFormulae;
        BOOL valid;
        
        enum Error
        {
                noError = 0, // everything ok
                dependencyError = 1, // dependency sequent invalid
                lineNumberError = 2, // line number sequent invalid
                formulaError = 3, // formula sequent invalid
        } errorCode;
}

I get "nested redefinition of 'enum Error'", (ii) "redeclaration of 'enum Error'" and (iii) redeclaration of enumerator 'noError'. So, I have two questions: is it possible to get each enum local to the class in which it is defined (so it does not seem to be "nested")? Second, is there a better strategy for defining human-readable error codes? Thanks.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to