c#/aspx error handling

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

    #1

    c#/aspx error handling

    i am trying to write aspx login system and the login process requires a
    validity check of username and password.

    i have been told that raising exception is costly, but i want a custom error
    message to be displayed depending on what error occurred (let's say: invalid
    username, invalid password, password must contain 5 or more characters,
    etc).

    at the moment, my login method is returning true/false depending on whether
    the login was succesful or not. however, if the login fails, how will my
    calling function know what error occurred without raising an exception?

    i know i could return numbers from the login method back to the calling
    function (where each number represents a different error), but then i would
    have to check the value of the number on every calling function that uses
    the login method, and write the appropritate error messages on EVERY calling
    function.

    is there a way i can write my code so i only have to write the error in the
    login function, and calling functions will pick up the error message if the
    login fails?

    thanks


  • Jerry III

    #2
    Re: c#/aspx error handling

    If you want to go the easy way just return a string instead of a boolean
    value. Null means success, anything else is the actual error message (or its
    resource id if you want to localize). But it's not a good security practice
    to show this info, it allows for a lot easier break-in (saying the password
    is incorrect means you have a valid login name and now you just need the
    password, giving out information on how long the password needs to be narrow
    down the search space dramatically and so on). If you want to be safe just
    show a generic "Invalid user name or password" message for failed logins.

    Jerry

    "suzy" <me@nospam.co m> wrote in message
    news:egnmSQkYDH A.1004@TK2MSFTN GP12.phx.gbl...[color=blue]
    > i am trying to write aspx login system and the login process requires a
    > validity check of username and password.
    >
    > i have been told that raising exception is costly, but i want a custom[/color]
    error[color=blue]
    > message to be displayed depending on what error occurred (let's say:[/color]
    invalid[color=blue]
    > username, invalid password, password must contain 5 or more characters,
    > etc).
    >
    > at the moment, my login method is returning true/false depending on[/color]
    whether[color=blue]
    > the login was succesful or not. however, if the login fails, how will my
    > calling function know what error occurred without raising an exception?
    >
    > i know i could return numbers from the login method back to the calling
    > function (where each number represents a different error), but then i[/color]
    would[color=blue]
    > have to check the value of the number on every calling function that uses
    > the login method, and write the appropritate error messages on EVERY[/color]
    calling[color=blue]
    > function.
    >
    > is there a way i can write my code so i only have to write the error in[/color]
    the[color=blue]
    > login function, and calling functions will pick up the error message if[/color]
    the[color=blue]
    > login fails?
    >
    > thanks
    >
    >[/color]


    Comment

    • suzy

      #3
      Re: c#/aspx error handling

      Yes I see what you're saying, but it's the theory I'm interested in. I just
      used the login as an example.

      What if I had a function that really did need to return the type of error
      that occurred. I could return null on success and the error message on
      failure, but what if the function was meant to return a dataset or
      something? How would I retrieve an error in that scenario?

      The only neat way I can think of doing it is to throw an exception, but
      that's too costly by the sounds of things.


      "Jerry III" <jerryiii@hotma il.com> wrote in message
      news:eqr5uxkYDH A.2632@TK2MSFTN GP09.phx.gbl...[color=blue]
      > If you want to go the easy way just return a string instead of a boolean
      > value. Null means success, anything else is the actual error message (or[/color]
      its[color=blue]
      > resource id if you want to localize). But it's not a good security[/color]
      practice[color=blue]
      > to show this info, it allows for a lot easier break-in (saying the[/color]
      password[color=blue]
      > is incorrect means you have a valid login name and now you just need the
      > password, giving out information on how long the password needs to be[/color]
      narrow[color=blue]
      > down the search space dramatically and so on). If you want to be safe just
      > show a generic "Invalid user name or password" message for failed logins.
      >
      > Jerry
      >
      > "suzy" <me@nospam.co m> wrote in message
      > news:egnmSQkYDH A.1004@TK2MSFTN GP12.phx.gbl...[color=green]
      > > i am trying to write aspx login system and the login process requires a
      > > validity check of username and password.
      > >
      > > i have been told that raising exception is costly, but i want a custom[/color]
      > error[color=green]
      > > message to be displayed depending on what error occurred (let's say:[/color]
      > invalid[color=green]
      > > username, invalid password, password must contain 5 or more characters,
      > > etc).
      > >
      > > at the moment, my login method is returning true/false depending on[/color]
      > whether[color=green]
      > > the login was succesful or not. however, if the login fails, how will[/color][/color]
      my[color=blue][color=green]
      > > calling function know what error occurred without raising an exception?
      > >
      > > i know i could return numbers from the login method back to the calling
      > > function (where each number represents a different error), but then i[/color]
      > would[color=green]
      > > have to check the value of the number on every calling function that[/color][/color]
      uses[color=blue][color=green]
      > > the login method, and write the appropritate error messages on EVERY[/color]
      > calling[color=green]
      > > function.
      > >
      > > is there a way i can write my code so i only have to write the error in[/color]
      > the[color=green]
      > > login function, and calling functions will pick up the error message if[/color]
      > the[color=green]
      > > login fails?
      > >
      > > thanks
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Anders Borum

        #4
        Re: c#/aspx error handling

        Hello!
        [color=blue]
        > The only neat way I can think of doing it is to throw an exception, but
        > that's too costly by the sounds of things.[/color]

        You could return use an enumeration value from the function. This would keep
        things pretty typesafe and you could handle the return value pretty easily.
        How about that?

        An error is not necessarily an exception. If you can handle and anticipate
        the error, it's generally not a good idea to throw an exception. Throwing
        exceptions automatically forces the users of your API to wrap a
        try/catch/finally block around each method.

        Or am I wrong? :-)

        --
        venlig hilsen / with regards
        anders borum
        --


        Comment

        • suzy

          #5
          Re: c#/aspx error handling

          Do you mean return an enum that contains the possible errors?

          This would work if the function fails, but what if my function was meant to
          return a dataset, boolean, etc if it succeeds?

          I know I could get around this by setting all my functions to return
          objects, rather than explicit types, but surely there must be a better way
          of raising errors up the call stack.

          In VB I would simply call Err.Raise with the appropriate error message.
          This would be raised to my calling function and it would check to see if the
          Err.Number is > 0 and display the Err.Message accordingly.


          "Anders Borum" <na@na.na> wrote in message
          news:OgEaINlYDH A.2352@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Hello!
          >[color=green]
          > > The only neat way I can think of doing it is to throw an exception, but
          > > that's too costly by the sounds of things.[/color]
          >
          > You could return use an enumeration value from the function. This would[/color]
          keep[color=blue]
          > things pretty typesafe and you could handle the return value pretty[/color]
          easily.[color=blue]
          > How about that?
          >
          > An error is not necessarily an exception. If you can handle and anticipate
          > the error, it's generally not a good idea to throw an exception. Throwing
          > exceptions automatically forces the users of your API to wrap a
          > try/catch/finally block around each method.
          >
          > Or am I wrong? :-)
          >
          > --
          > venlig hilsen / with regards
          > anders borum
          > --
          >
          >[/color]


          Comment

          • Hans Kesting

            #6
            Re: c#/aspx error handling

            I think that there is no generic answer (apart from "it depends..").

            If I remember correctly from previous threads, exceptions are only
            "expensive" when actually thrown.

            So, if you can handle "expected errorconditions " (like "username/password
            combination not correct"), especially ones that could occur often, without
            exceptions, please do.
            If there is an exceptional situation, that should not occur at all ("a
            needed file
            is not where expected"), then there is no problem throwing exceptions.

            The exception mechanism is created epsecially for situations where you
            need to signal some error-condition, without limits to the regular output
            of the function.


            Hans Kesting

            "suzy" <me@nospam.co m> wrote in message
            news:%23qxVUSlY DHA.2960@tk2msf tngp13.phx.gbl. ..[color=blue]
            > Do you mean return an enum that contains the possible errors?
            >
            > This would work if the function fails, but what if my function was meant[/color]
            to[color=blue]
            > return a dataset, boolean, etc if it succeeds?
            >
            > I know I could get around this by setting all my functions to return
            > objects, rather than explicit types, but surely there must be a better way
            > of raising errors up the call stack.
            >
            > In VB I would simply call Err.Raise with the appropriate error message.
            > This would be raised to my calling function and it would check to see if[/color]
            the[color=blue]
            > Err.Number is > 0 and display the Err.Message accordingly.
            >
            >
            > "Anders Borum" <na@na.na> wrote in message
            > news:OgEaINlYDH A.2352@TK2MSFTN GP12.phx.gbl...[color=green]
            > > Hello!
            > >[color=darkred]
            > > > The only neat way I can think of doing it is to throw an exception,[/color][/color][/color]
            but[color=blue][color=green][color=darkred]
            > > > that's too costly by the sounds of things.[/color]
            > >
            > > You could return use an enumeration value from the function. This would[/color]
            > keep[color=green]
            > > things pretty typesafe and you could handle the return value pretty[/color]
            > easily.[color=green]
            > > How about that?
            > >
            > > An error is not necessarily an exception. If you can handle and[/color][/color]
            anticipate[color=blue][color=green]
            > > the error, it's generally not a good idea to throw an exception.[/color][/color]
            Throwing[color=blue][color=green]
            > > exceptions automatically forces the users of your API to wrap a
            > > try/catch/finally block around each method.
            > >
            > > Or am I wrong? :-)
            > >
            > > --
            > > venlig hilsen / with regards
            > > anders borum
            > > --
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Jerry III

              #7
              Re: c#/aspx error handling

              I agree, instead of trying to come up with complicated schemes on how to
              handle errors it's just easier to throw exceptions. In most cases simplicity
              and readability of the code is more precious then few [hundred] CPU cycles,
              you can easily upgrade your server and it pays off once you have to go back
              to the code or add more people to the project - if it's easier to understand
              the logic it saves a lot of time. And people time is lot more expensive than
              server hardware...

              Jerry

              "John Sparrow" <jsparrow@eccle scollege.ac.uk> wrote in message
              news:1357b958.0 308140518.5c887 fc7@posting.goo gle.com...[color=blue]
              > Personally I would throw an exception. It's true they are *relatively*
              > expensive and you shouldn't routinely throw and catch exceptions in
              > loops (for example), but you're not going to get hundreds of failed
              > logins a second, are you??!
              >
              > If you don't want to define try..catch blocks everywhere, define a
              > Application_Err or() method in Global.asax.cs
              >
              > Also, you could define a custom error page in web.config, ie
              > <customErrors defaultRedirect ="SysErrorPage. aspx" mode="RemoteOnl y" />
              >
              > This gets called after Application_Err or() i think. So I use the
              > method to record exception details in the database, then present the
              > user with a nice message in the custom error page.
              >
              > Don't be frightened of using exceptions when something doesn't go to
              > plan. It's what they're there for.
              >
              > ie. every time we call Response.Redire ct() an 'silent' exception is
              > raised.
              >
              > John
              >
              > "suzy" <me@nospam.co m> wrote in message[/color]
              news:<e9Zri2kYD HA.2352@TK2MSFT NGP12.phx.gbl>. ..[color=blue][color=green]
              > > Yes I see what you're saying, but it's the theory I'm interested in. I[/color][/color]
              just[color=blue][color=green]
              > > used the login as an example.
              > >
              > > What if I had a function that really did need to return the type of[/color][/color]
              error[color=blue][color=green]
              > > that occurred. I could return null on success and the error message on
              > > failure, but what if the function was meant to return a dataset or
              > > something? How would I retrieve an error in that scenario?[/color][/color]


              Comment

              • Robbie Harris

                #8
                Re: c#/aspx error handling

                lots of comments on this, but first there's the need to differentiate
                between an *exception* and an expected state condition in your application.
                invalid usernames, passwords, and failed field validations are not
                necessarily exceptions. if they're not (and i'd suggest in your case they
                arent) then yes, they would be relatively expensive if they were handled as
                such. where such states will frequently occur (like your login form) you
                should deal with them within the body of your code. there's nothing wrong
                returning a boolean - false allows the UI to display a generic
                'username/password combination failed message', which - as already pointed
                out in this thread - is good practise. if you, as the developer, really need
                to know what went wrong, write a trace entry including the values the user
                posted.

                from the thread you presumably have a class calling a login class and want
                to branch depending on a returned value from that class. but you probably
                shouldnt branch other than a if boolean == IsAuthenticated () - keep the
                logic and expected state failures encapsulated in your login class - which
                should raise exceptions out to the consumers only when expections occur -
                such as the authentication provider not being accessible. indeed there's a
                case to be made for not even returning that since such exceptions can
                provide security sensitive data that could make its way back to the UI -
                i've worked on a number of projects where we returned only a boolen, no
                excpetions, from the authentication class.

                r.

                "suzy" <me@nospam.co m> wrote in message
                news:egnmSQkYDH A.1004@TK2MSFTN GP12.phx.gbl...[color=blue]
                > i am trying to write aspx login system and the login process requires a
                > validity check of username and password.
                >
                > i have been told that raising exception is costly, but i want a custom[/color]
                error[color=blue]
                > message to be displayed depending on what error occurred (let's say:[/color]
                invalid[color=blue]
                > username, invalid password, password must contain 5 or more characters,
                > etc).
                >
                > at the moment, my login method is returning true/false depending on[/color]
                whether[color=blue]
                > the login was succesful or not. however, if the login fails, how will my
                > calling function know what error occurred without raising an exception?
                >
                > i know i could return numbers from the login method back to the calling
                > function (where each number represents a different error), but then i[/color]
                would[color=blue]
                > have to check the value of the number on every calling function that uses
                > the login method, and write the appropritate error messages on EVERY[/color]
                calling[color=blue]
                > function.
                >
                > is there a way i can write my code so i only have to write the error in[/color]
                the[color=blue]
                > login function, and calling functions will pick up the error message if[/color]
                the[color=blue]
                > login fails?
                >
                > thanks
                >
                >[/color]


                Comment

                • Jerry III

                  #9
                  Re: c#/aspx error handling

                  Now we're down to just playing on words but one could argue that invalid
                  authentication is an exception in the process of logging in. It really
                  depends on your point of view, you could argue that running out of disk
                  space while writing a file is not an exception as you should check if you
                  have enough space before you write, much like you check for user name and
                  password before you create a login ticket.

                  As for Kevin's post - even if you write the most efficient code possible it
                  will stay vulnerable to DoS attacks. I think most of the time the balance
                  tips towards writing clean code, not fast code. You're going to have less
                  errors and your code is going to be a lot easier to maintain. In most cases
                  that's worth more than speed, look at Microsoft's download center,
                  theoretically it's incredibly inefficient in the way it works (read about it
                  in Microsoft's backstage articles) but that's more than outweighed by the
                  manageability of the code and the whole system.

                  Jerry

                  "Robbie Harris" <robbie_harris@ hotmail.com> wrote in message
                  news:bhgvi6$bbe $1@sparta.btint ernet.com...[color=blue]
                  > lots of comments on this, but first there's the need to differentiate
                  > between an *exception* and an expected state condition in your[/color]
                  application.[color=blue]
                  > invalid usernames, passwords, and failed field validations are not
                  > necessarily exceptions. if they're not (and i'd suggest in your case they
                  > arent) then yes, they would be relatively expensive if they were handled[/color]
                  as[color=blue]
                  > such. where such states will frequently occur (like your login form) you
                  > should deal with them within the body of your code. there's nothing wrong
                  > returning a boolean - false allows the UI to display a generic
                  > 'username/password combination failed message', which - as already pointed
                  > out in this thread - is good practise. if you, as the developer, really[/color]
                  need[color=blue]
                  > to know what went wrong, write a trace entry including the values the user
                  > posted.
                  >
                  > from the thread you presumably have a class calling a login class and want
                  > to branch depending on a returned value from that class. but you probably
                  > shouldnt branch other than a if boolean == IsAuthenticated () - keep the
                  > logic and expected state failures encapsulated in your login class - which
                  > should raise exceptions out to the consumers only when expections occur -
                  > such as the authentication provider not being accessible. indeed there's a
                  > case to be made for not even returning that since such exceptions can
                  > provide security sensitive data that could make its way back to the UI -
                  > i've worked on a number of projects where we returned only a boolen, no
                  > excpetions, from the authentication class.
                  >
                  > r.
                  >
                  > "suzy" <me@nospam.co m> wrote in message
                  > news:egnmSQkYDH A.1004@TK2MSFTN GP12.phx.gbl...[color=green]
                  > > i am trying to write aspx login system and the login process requires a
                  > > validity check of username and password.
                  > >
                  > > i have been told that raising exception is costly, but i want a custom[/color]
                  > error[color=green]
                  > > message to be displayed depending on what error occurred (let's say:[/color]
                  > invalid[color=green]
                  > > username, invalid password, password must contain 5 or more characters,
                  > > etc).
                  > >
                  > > at the moment, my login method is returning true/false depending on[/color]
                  > whether[color=green]
                  > > the login was succesful or not. however, if the login fails, how will[/color][/color]
                  my[color=blue][color=green]
                  > > calling function know what error occurred without raising an exception?
                  > >
                  > > i know i could return numbers from the login method back to the calling
                  > > function (where each number represents a different error), but then i[/color]
                  > would[color=green]
                  > > have to check the value of the number on every calling function that[/color][/color]
                  uses[color=blue][color=green]
                  > > the login method, and write the appropritate error messages on EVERY[/color]
                  > calling[color=green]
                  > > function.
                  > >
                  > > is there a way i can write my code so i only have to write the error in[/color]
                  > the[color=green]
                  > > login function, and calling functions will pick up the error message if[/color]
                  > the[color=green]
                  > > login fails?
                  > >
                  > > thanks
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Robbie Harris

                    #10
                    Re: c#/aspx error handling

                    oh i agree that knowing when to raise an exception and when not is a matter
                    of judgement, and in mine an invalid username, password or field validation
                    is not an exception condition. the best practises are here:

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

                    key among them:

                    * All code paths that result in an exception should provide a method to
                    check for success without throwing an exception
                    * Do not use exceptions for normal or expected errors, or for normal flow of
                    control.
                    * Do not expose secure information in exception messages.
                    * Design classes so that in the normal course of use an exception will never
                    be thrown.

                    r.

                    "John Sparrow" <jsparrow@eccle scollege.ac.uk> wrote in message
                    news:1357b958.0 308150126.72842 4ba@posting.goo gle.com...[color=blue]
                    > Couldn't agree more - exceptions are there to cope with error
                    > conditions, and to me a failed login is an error condition. They're
                    > not simply about major / rare / critical failures of the application.
                    > The response.redire ct() example in the framework proves this.
                    >
                    > Often, I use both strategies: check something should work, try it, and
                    > if it doesn't raise an exception. That way if I forget to check I'm
                    > still protected!
                    >
                    > Exceptions usually aid readibility, security and robustness of code
                    > (especially when you design them in from the beginning). For me thats
                    > the main factor.
                    >[/color]
                    <snip>
                    [color=blue]
                    > John
                    >
                    > "Jerry III" <jerryiii@hotma il.com> wrote in message[/color]
                    news:<uBhPcvrYD HA.2464@TK2MSFT NGP09.phx.gbl>. ..[color=blue][color=green]
                    > > Now we're down to just playing on words but one could argue that invalid
                    > > authentication is an exception in the process of logging in. It really
                    > > depends on your point of view, you could argue that running out of disk
                    > > space while writing a file is not an exception as you should check if[/color][/color]
                    you[color=blue][color=green]
                    > > have enough space before you write, much like you check for user name[/color][/color]
                    and[color=blue][color=green]
                    > > password before you create a login ticket.[/color][/color]


                    Comment

                    • Jerry III

                      #11
                      Re: c#/aspx error handling

                      Yet Microsoft themselves break three of these four quoted rules with
                      Response.Redire ct. You have to realize that these rules are suggestions, not
                      dogmas. And there are going to be cases when it's better to code against
                      Microsoft's recommendations .

                      Jerry

                      "Robbie Harris" <robbie_harris@ hotmail.com> wrote in message
                      news:bhifsu$623 $1@sparta.btint ernet.com...[color=blue]
                      > oh i agree that knowing when to raise an exception and when not is a[/color]
                      matter[color=blue]
                      > of judgement, and in mine an invalid username, password or field[/color]
                      validation[color=blue]
                      > is not an exception condition. the best practises are here:
                      >
                      >[/color]
                      http://msdn.microsoft.com/library/de...guidelines.asp[color=blue]
                      >
                      > key among them:
                      >
                      > * All code paths that result in an exception should provide a method to
                      > check for success without throwing an exception
                      > * Do not use exceptions for normal or expected errors, or for normal flow[/color]
                      of[color=blue]
                      > control.
                      > * Do not expose secure information in exception messages.
                      > * Design classes so that in the normal course of use an exception will[/color]
                      never[color=blue]
                      > be thrown.
                      >
                      > r.
                      >
                      > "John Sparrow" <jsparrow@eccle scollege.ac.uk> wrote in message
                      > news:1357b958.0 308150126.72842 4ba@posting.goo gle.com...[color=green]
                      > > Couldn't agree more - exceptions are there to cope with error
                      > > conditions, and to me a failed login is an error condition. They're
                      > > not simply about major / rare / critical failures of the application.
                      > > The response.redire ct() example in the framework proves this.
                      > >
                      > > Often, I use both strategies: check something should work, try it, and
                      > > if it doesn't raise an exception. That way if I forget to check I'm
                      > > still protected!
                      > >
                      > > Exceptions usually aid readibility, security and robustness of code
                      > > (especially when you design them in from the beginning). For me thats
                      > > the main factor.
                      > >[/color]
                      > <snip>
                      >[color=green]
                      > > John
                      > >
                      > > "Jerry III" <jerryiii@hotma il.com> wrote in message[/color]
                      > news:<uBhPcvrYD HA.2464@TK2MSFT NGP09.phx.gbl>. ..[color=green][color=darkred]
                      > > > Now we're down to just playing on words but one could argue that[/color][/color][/color]
                      invalid[color=blue][color=green][color=darkred]
                      > > > authentication is an exception in the process of logging in. It really
                      > > > depends on your point of view, you could argue that running out of[/color][/color][/color]
                      disk[color=blue][color=green][color=darkred]
                      > > > space while writing a file is not an exception as you should check if[/color][/color]
                      > you[color=green][color=darkred]
                      > > > have enough space before you write, much like you check for user name[/color][/color]
                      > and[color=green][color=darkred]
                      > > > password before you create a login ticket.[/color][/color]
                      >
                      >[/color]


                      Comment

                      • Kevin Spencer

                        #12
                        Re: c#/aspx error handling

                        You missed my point.

                        --
                        HTH,

                        Kevin Spencer
                        Microsoft MVP
                        ..Net Developer
                        All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

                        Neither a follower nor a lender be.

                        "Jerry III" <jerryiii@hotma il.com> wrote in message
                        news:uvqDs9CZDH A.1280@tk2msftn gp13.phx.gbl...[color=blue]
                        > Don't have to tell me that. The same can be said for the login class,
                        > whatever implements the login process should throw exceptions if there's[/color]
                        an[color=blue]
                        > error processing the login and the application using it should catch it.
                        > Even though there's not a clear line between the application and the
                        > authentication business logic. In the end it's a lot easier to use code[/color]
                        that[color=blue]
                        > throws exceptions in case of an invalid user name or password than one[/color]
                        that[color=blue]
                        > returns an error value (you'll eventually end up returning something[/color]
                        similar[color=blue]
                        > to Exception class object anyways).
                        >
                        > Jerry
                        >
                        > "Kevin Spencer" <kevin@takempis .com> wrote in message
                        > news:eoJCd01YDH A.3444@tk2msftn gp13.phx.gbl...[color=green]
                        > > Actually, when designing a set of classes for use in developing programs
                        > > (such as the CLR), throwing exceptions is something those classes SHOULD[/color]
                        > do.[color=green]
                        > > The developer that uses these classes in an application should ensure[/color][/color]
                        that[color=blue][color=green]
                        > > the _application_ doesn't throw exceptions, by handling them.
                        > >
                        > > --
                        > > HTH,
                        > >
                        > > Kevin Spencer
                        > > Microsoft MVP
                        > > .Net Developer
                        > > http://www.takempis.com
                        > > Neither a follower nor a lender be.
                        > >
                        > > "Jerry III" <jerryiii@hotma il.com> wrote in message
                        > > news:%23DHYfY1Y DHA.1580@tk2msf tngp13.phx.gbl. ..[color=darkred]
                        > > > Yet Microsoft themselves break three of these four quoted rules with
                        > > > Response.Redire ct. You have to realize that these rules are[/color][/color][/color]
                        suggestions,[color=blue][color=green]
                        > > not[color=darkred]
                        > > > dogmas. And there are going to be cases when it's better to code[/color][/color][/color]
                        against[color=blue][color=green][color=darkred]
                        > > > Microsoft's recommendations .
                        > > >
                        > > > Jerry
                        > > >
                        > > > "Robbie Harris" <robbie_harris@ hotmail.com> wrote in message
                        > > > news:bhifsu$623 $1@sparta.btint ernet.com...
                        > > > > oh i agree that knowing when to raise an exception and when not is a
                        > > > matter
                        > > > > of judgement, and in mine an invalid username, password or field
                        > > > validation
                        > > > > is not an exception condition. the best practises are here:
                        > > > >
                        > > > >
                        > > >[/color]
                        > >[/color]
                        >[/color]
                        http://msdn.microsoft.com/library/de...guidelines.asp[color=blue][color=green][color=darkred]
                        > > > >
                        > > > > key among them:
                        > > > >
                        > > > > * All code paths that result in an exception should provide a method[/color][/color]
                        > to[color=green][color=darkred]
                        > > > > check for success without throwing an exception
                        > > > > * Do not use exceptions for normal or expected errors, or for normal[/color]
                        > > flow[color=darkred]
                        > > > of
                        > > > > control.
                        > > > > * Do not expose secure information in exception messages.
                        > > > > * Design classes so that in the normal course of use an exception[/color][/color][/color]
                        will[color=blue][color=green][color=darkred]
                        > > > never
                        > > > > be thrown.
                        > > > >
                        > > > > r.
                        > > > >
                        > > > > "John Sparrow" <jsparrow@eccle scollege.ac.uk> wrote in message
                        > > > > news:1357b958.0 308150126.72842 4ba@posting.goo gle.com...
                        > > > > > Couldn't agree more - exceptions are there to cope with error
                        > > > > > conditions, and to me a failed login is an error condition.[/color][/color][/color]
                        They're[color=blue][color=green][color=darkred]
                        > > > > > not simply about major / rare / critical failures of the[/color][/color]
                        > application.[color=green][color=darkred]
                        > > > > > The response.redire ct() example in the framework proves this.
                        > > > > >
                        > > > > > Often, I use both strategies: check something should work, try it,[/color][/color]
                        > and[color=green][color=darkred]
                        > > > > > if it doesn't raise an exception. That way if I forget to check[/color][/color][/color]
                        I'm[color=blue][color=green][color=darkred]
                        > > > > > still protected!
                        > > > > >
                        > > > > > Exceptions usually aid readibility, security and robustness of[/color][/color][/color]
                        code[color=blue][color=green][color=darkred]
                        > > > > > (especially when you design them in from the beginning). For me[/color][/color]
                        > thats[color=green][color=darkred]
                        > > > > > the main factor.
                        > > > > >
                        > > > > <snip>
                        > > > >
                        > > > > > John
                        > > > > >
                        > > > > > "Jerry III" <jerryiii@hotma il.com> wrote in message
                        > > > > news:<uBhPcvrYD HA.2464@TK2MSFT NGP09.phx.gbl>. ..
                        > > > > > > Now we're down to just playing on words but one could argue that
                        > > > invalid
                        > > > > > > authentication is an exception in the process of logging in. It[/color]
                        > > really[color=darkred]
                        > > > > > > depends on your point of view, you could argue that running out[/color][/color][/color]
                        of[color=blue][color=green][color=darkred]
                        > > > disk
                        > > > > > > space while writing a file is not an exception as you should[/color][/color][/color]
                        check[color=blue][color=green]
                        > > if[color=darkred]
                        > > > > you
                        > > > > > > have enough space before you write, much like you check for user[/color]
                        > > name[color=darkred]
                        > > > > and
                        > > > > > > password before you create a login ticket.
                        > > > >
                        > > > >
                        > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        Working...