By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,173 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,173 IT Pros & Developers. It's quick & easy.

Enums & Flags

P: n/a
I am running loop with calls different functions such as
SetHomeDrive, AddUserToGroup etc. Now if any of the
functions fails, I am just catching and throwing a new
error like throw new Exception("Failed to Set Home Drive")
etc.

All these errors which are propelled back to my loop are
then logged to file. Even if an error occours in one ore
more function, the loop continues execution so I deally I
would like to have unique flag for each errror, which can
be OR ed each time an error occurs and finally at the end
of my loop find from the error flag what all errors
occured. How can I acheive this.

Thanks,

Rajesh Abraham Chacko
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Rajesh,
Generally you should not be raising System.Exception directly, you should
raise a different existing exception that is appropriate for the error or
you should define one of your own.

In this case I would define a new Exception class that has an enum property
for your unique flag. Define this unique flag as an Enum that has the Flags
attribute. Remember to set the values of the Enum to powers of 2: 1, 2, 4,
8, 16, 32, 64, 128... This exception class should derive from
System.ApplicationException. At the very least I would give it a constructor
that accepted this Enum, and a text string. In the main loop I would catch
this type of Exception, Or-ing the value with an accumulator.

See "Error Raising and Handling Guidelines" in the Design Guidelines for
Class Library Developers.

http://msdn.microsoft.com/library/de...guidelines.asp

Hope this helps
Jay

"Rajesh Abraham" <ch******@hotmail.com> wrote in message
news:05****************************@phx.gbl...
I am running loop with calls different functions such as
SetHomeDrive, AddUserToGroup etc. Now if any of the
functions fails, I am just catching and throwing a new
error like throw new Exception("Failed to Set Home Drive")
etc.

All these errors which are propelled back to my loop are
then logged to file. Even if an error occours in one ore
more function, the loop continues execution so I deally I
would like to have unique flag for each errror, which can
be OR ed each time an error occurs and finally at the end
of my loop find from the error flag what all errors
occured. How can I acheive this.

Thanks,

Rajesh Abraham Chacko

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.