Enums & Flags

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajesh Abraham

    #1

    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("Fail ed 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
  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: Enums & Flags

    Rajesh,
    Generally you should not be raising System.Exceptio n 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.Applicat ionException. 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" <chacko97@hotma il.com> wrote in message
    news:057101c355 4e$7321c970$a10 1280a@phx.gbl.. .[color=blue]
    > 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("Fail ed 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[/color]


    Comment

    Working...