How to filter errors in programs? During a development, the supervisor asked me to write an upload code. After I finished writing, the supervisor said that I did not perform filtering error processing. In writing a program, which situations should I filter errors? ------ Solution -------------------- be considerate and prompt troubleshooting for possible situations. ------ Solution ------------------ for example, the simplest one, the parameters are not passed completely. ------ How does the solution filter errors in the program?
During a development, the supervisor asked me to write an upload code.
After I finished writing, the supervisor said that I did not perform filtering error processing.
In writing a program, which situations should I filter errors?
------ Solution --------------------
Be considerate and prompt troubleshooting for possible situations.
------ Solution --------------------
For example, the simplest parameter is not completely transmitted.
------ Solution --------------------
Most of the code you see in books or on the Internet is the principle code.
It assumes that the involved environment and parameters are correct and reasonable. Therefore, the troubleshooting mechanism is not added to improve the readability of the code.
According to the software engineering rules, the actual running code must undergo various tests, and some errors caused by external factors will be exposed during the test.
It is unlikely that you will know in advance where problems may occur. even if you have years of development experience, you will also miss some minor problems.
The manual provides the main troubleshooting code for your project.
------ Solution --------------------
Just do not assume that the parameters submitted by the user are valid. check the parameters submitted by the user with this mentality.
------ Solution --------------------
Never trust user data, even if he/she is your mother