Errors, exceptions and asserts

This is a discussion on Errors, exceptions and asserts within the C++ Programming forums, part of the General Programming Boards category; The following is a member function: void strength(unsigned int); With it, an user of the class can change the strength ...

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535

    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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,796
    >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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21