• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Nested Enum Error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nested Enum Error


  • Subject: Re: Nested Enum Error
  • From: Andrew Merenbach <email@hidden>
  • Date: Thu, 20 Mar 2008 21:00:32 -0700

Hi, there,

I'm afraid that I can't offer the solution that you desire, but I might suggest using class-specific error-code names, as Apple does with notifications, constants, and such.

enum Error{
	KDODeductionLineNoError = 0,
	KDODeductionLineDependencyExistError = 1,
	// etc.
} errorCode;

And then do the same for any subclasses, with the full name of the class preceding the error code string.

(As a side note, the "KDO" string that I prepended to the error code examples stands for K. Darcy Otto.)

Cheers,
	Andrew

On Mar 20, 2008, at 8: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 (email@hidden)

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:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >Nested Enum Error (From: "K. Darcy Otto" <email@hidden>)

  • Prev by Date: Nested Enum Error
  • Next by Date: Re: Nested Enum Error
  • Previous by thread: Nested Enum Error
  • Next by thread: Re: Nested Enum Error
  • Index(es):
    • Date
    • Thread