Thread: Errors, exceptions and asserts

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    Errors, exceptions and asserts

    The following is a member function:

    void strength(unsigned int);

    With it, an user of the class can change the strength data member. However the parameter range is [1, 20].

    What do you suggest as an error reporting mechanism taking into consideration that the argument passed will never come directly from the application user input and failure to comply with the requirement is a coding error?

    An assert?
    Throwing std:: out_of_range?
    Changing return type to bool and return false? (ugh?)

    This is in line with a post I will be making shortly in the hopes someone can help me define an error handling mechanism.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >the argument passed will never come directly from the application user input and failure to
    >comply with the requirement is a coding error?
    An assertion is the most intuitive in this case.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed