473,325 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Enums & Flags

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
1 4181
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
3
by: Mike Scott | last post by:
What is the best way to index an array by an enum. Pascal has a nice feature in that arrays can be indexed by an enum, for example type ButtonType = ( Left, Middle, Right ) ; var buttons :...
2
by: Kyle Novak | last post by:
What I want to do is take the values of an enum and have a related textual description for each item. For example, if I have an enum declared as the following... public enum EqualityOperator...
5
by: DMitchell | last post by:
Is there any way of getting a public enumeration to be generated into a web service proxy?
7
by: Bit Twiddler | last post by:
I have a home grown bit vector and I keep oscillating between what I use access individual bits. For example, is is better to do this: const int BIT_1 = 1; const int BIT_2 = 2; .... int...
9
by: userblue | last post by:
Hi Does anyone know if there is a way to define what is effectively a single globally visible, enumerated list whilst actually defining the entries across several different modules? or somehow do...
3
by: J055 | last post by:
Hi The function below accepts an Enum value 'AccountRoles' and should return an array of Permissions which is also an Enum. When the AccountRoles is AccountRoles.Administrator it should always...
2
by: Rain | last post by:
Im using C#3.0 and in my book of words it tells me that when I use the I should be able to call ToString() on a combined enumeration and have it emit a series of strings. IE public enum ...
0
by: Cousin Stanley | last post by:
I've never had any problems at all with message threading using xpn .... Since I've always used Keep SubThread instead of Watch SubThread, I have no personal experience with the watch flags...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.