Board index » cppbuilder » How to handle problems in a header file.
How to handle problems in a header file.
2005-10-01 08:52:18 AM
I have written a matrix class that is now happily compiling, but there is a certain issue in my mind that is lingering. How should I handle the following problem:
Matrix is sent by user through a call from user code to a matrix inversion routine in header file. Header file code checks and discovers that matrix is not invertible. I have at least a few options.
1. Issue an error statement and return the matrix that was sent.
2. Issue an error statement and return the partially inverted matrix.
3. Issue an error statement and return a completely different matrix, such as a ones or zeroes matrix, although this will probably cause the user's code to experience another error.
4. Program the header file to exit after experiencing this error.
I have a second level of inquiry. If I am writing a header file for general purposes, how do I send an error to the screen without being sensitive to whether the user is using Borland C++ 4.51, VC++, or Borland Builder? If this is a DOS application that is calling the header, would I employ a "printf" or "cout" statement or a "msgbox" in the header file? I realize that the "msgbox" is not an option for a DOS app, so there must be a way to either detect the OS and use some sort of switch, or use a generic message sending routine that requires a confirmation by the user, such as "okay", as in, "okay, I know that a problem occurred, and will not believe anything that my code produces as subsequent results".
I would very much appreciate some expert insight into how to handle these two, related questions. I have to return some matrix, or the compiler isn't happy. I need to send a message describing an error, or the user might be inclined to believe the results. I would be tempted to exit to insure that no erroneous results based upon a partially inverted (and uninvertable) matrix are misinterpreted as being valid by the user, but such an option is not usually considered suitable among Windows programmers.
Thank you in advance for any advice that you might offer.