It is important for us to identify the difference between error and problem statement. While using Custom error we need to provide nice, easy to understand the message to the user. Otherwise, the purpose to use custom, the user-defined error goes in vain.
Rules to generate Custom message:
- Do not use rude or harsh words.
- Use nice words to communicate the error in a descriptive way.
- Try providing a solution or a pointer on how to solve the current issue.
- Apologize for the error.
- Try putting code to recover from the error.
The objective of custom error is to communicate the user that the person has done something against the basic assumption of the code.
Capture or Not to Capture an Error
It is also very important point to decide if we need to capture the error or we should not capture in the script. If we are building small utility to automate something and the script will not be part of the larger framework, we often do not capture the error.
But if you are building a script that will be part of the automation framework, we need to capture the Error messages.It only not only help in debugging but also help us to understand the root cause of the error.