Throwing ArgumentExceptions in Property Setters

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

    #1

    Throwing ArgumentExceptions in Property Setters

    Quick question.

    When you guys throw an ArgumentExcepti on (or one of its deriviatives)
    from a property setter, what do you use as the argument to the
    exception's constructor? For instance:

    Throw New ArgumentOutOfRa ngeException("v alue")

    Passing "value" seems less helpful than it should be; you have to
    examine the call stack to determine which property threw the
    exception. I am sorely tempted in many cases to use the name of the
    property, but I know that this isn't the recommended practice.

    On the other hand, I've considered a series of exception classes
    similar to ArgumentExcepti on: PropertyExcepti on. These would take the
    property name rather than the argument name. That way, the name
    semantics are preserved and everyone's happy.

    How do you guys deal with this scenario? Do you just suck it up and
    use "value"?

    Thanks!

  • RobinS

    #2
    Re: Throwing ArgumentExcepti ons in Property Setters

    This has already been answered in another newsgroup. If you want to post to
    multiple newsgroups, please post all of them at once. This way, if it gets
    answered in one group, the people in the other groups can see it, and can
    chime in, or know it's been answered so they can go help someone whose
    question has not been answered.

    Thanks,
    Robin S.
    -------------------------------
    "Mike Hofer" <kchighland@gma il.comwrote in message
    news:1177353487 .439739.301180@ b58g2000hsg.goo glegroups.com.. .
    Quick question.
    >
    When you guys throw an ArgumentExcepti on (or one of its deriviatives)
    from a property setter, what do you use as the argument to the
    exception's constructor? For instance:
    >
    Throw New ArgumentOutOfRa ngeException("v alue")
    >
    Passing "value" seems less helpful than it should be; you have to
    examine the call stack to determine which property threw the
    exception. I am sorely tempted in many cases to use the name of the
    property, but I know that this isn't the recommended practice.
    >
    On the other hand, I've considered a series of exception classes
    similar to ArgumentExcepti on: PropertyExcepti on. These would take the
    property name rather than the argument name. That way, the name
    semantics are preserved and everyone's happy.
    >
    How do you guys deal with this scenario? Do you just suck it up and
    use "value"?
    >
    Thanks!
    >

    Comment

    • Mike Hofer

      #3
      Re: Throwing ArgumentExcepti ons in Property Setters

      On Apr 24, 3:02 am, "RobinS" <Rob...@NoSpam. yah.nonewrote:
      This has already been answered in another newsgroup. If you want to post to
      multiple newsgroups, please post all of them at once. This way, if it gets
      answered in one group, the people in the other groups can see it, and can
      chime in, or know it's been answered so they can go help someone whose
      question has not been answered.
      >
      Thanks,
      Robin S.
      -------------------------------"Mike Hofer" <kchighl...@gma il.comwrote in message
      >
      news:1177353487 .439739.301180@ b58g2000hsg.goo glegroups.com.. .
      >
      >
      >
      Quick question.
      >
      When you guys throw an ArgumentExcepti on (or one of its deriviatives)
      from a property setter, what do you use as the argument to the
      exception's constructor? For instance:
      >
      Throw New ArgumentOutOfRa ngeException("v alue")
      >
      Passing "value" seems less helpful than it should be; you have to
      examine the call stack to determine which property threw the
      exception. I am sorely tempted in many cases to use the name of the
      property, but I know that this isn't the recommended practice.
      >
      On the other hand, I've considered a series of exception classes
      similar to ArgumentExcepti on: PropertyExcepti on. These would take the
      property name rather than the argument name. That way, the name
      semantics are preserved and everyone's happy.
      >
      How do you guys deal with this scenario? Do you just suck it up and
      use "value"?
      >
      Thanks!- Hide quoted text -
      >
      - Show quoted text -
      Hi Robin,

      Normally, I don't cross-post, and certainly not manually. Please
      forgive me for doing so. I use Google to peruse groups at work, and
      when I posted the question to the other group, it didn't appear for
      *hours*. I assumed Google ate the post. So I reposted it here.

      I'll go look for it over there.

      Thanks!

      Comment

      • RobinS

        #4
        Re: Throwing ArgumentExcepti ons in Property Setters


        "Mike Hofer" <kchighland@gma il.comwrote in message
        news:1177511093 .468928.166920@ n35g2000prd.goo glegroups.com.. .
        On Apr 24, 3:02 am, "RobinS" <Rob...@NoSpam. yah.nonewrote:
        >This has already been answered in another newsgroup. If you want to post
        >to
        >multiple newsgroups, please post all of them at once. This way, if it
        >gets
        >answered in one group, the people in the other groups can see it, and
        >can
        >chime in, or know it's been answered so they can go help someone whose
        >question has not been answered.
        >>
        >Thanks,
        >Robin S.
        >-------------------------------"Mike Hofer" <kchighl...@gma il.comwrote
        >in message
        >>
        >news:117735348 7.439739.301180 @b58g2000hsg.go oglegroups.com. ..
        >>
        >>
        >>
        Quick question.
        >>
        When you guys throw an ArgumentExcepti on (or one of its deriviatives)
        from a property setter, what do you use as the argument to the
        exception's constructor? For instance:
        >>
        Throw New ArgumentOutOfRa ngeException("v alue")
        >>
        Passing "value" seems less helpful than it should be; you have to
        examine the call stack to determine which property threw the
        exception. I am sorely tempted in many cases to use the name of the
        property, but I know that this isn't the recommended practice.
        >>
        On the other hand, I've considered a series of exception classes
        similar to ArgumentExcepti on: PropertyExcepti on. These would take the
        property name rather than the argument name. That way, the name
        semantics are preserved and everyone's happy.
        >>
        How do you guys deal with this scenario? Do you just suck it up and
        use "value"?
        >>
        Thanks!- Hide quoted text -
        >>
        >- Show quoted text -
        >
        Hi Robin,
        >
        Normally, I don't cross-post, and certainly not manually. Please
        forgive me for doing so. I use Google to peruse groups at work, and
        when I posted the question to the other group, it didn't appear for
        *hours*. I assumed Google ate the post. So I reposted it here.
        >
        I'll go look for it over there.
        >
        Thanks!
        >
        It's okay, ship happens. I only mentioned it because I think I see you here
        frequently, and would hate for you to get in the habit. Plus, I was wearing
        my cranky pants. No offense intended.

        Robin S.


        Comment

        Working...