Add error handling in as many places as possible

Source: Internet
Author: User

Today, I encountered a very strange problem. I have tested a piece of code I have written many times and I have been using it to think that this piece of code is already very stable. But today I updated the database result. This Code turns into a dead code. I really don't believe in my own eyes, however, there is no way to find out, or find the bug, ah, and finally found that it was a variable because of changing the Library's initial value variable, resulting in a pointer being assigned a value without being assigned to the pointer. The following points are summarized:

1. In the switch... case... default statement structure, if there is nothing to do with the default statement, add an asserted.
2. If... else if your thinking is that there must be one of these two situations, you should add one more else.
To avoid your situation today, you can add an asserted in else.

 

If (pmonitorguiframe-> gsysmod. gmonitorconfig. recsweepspeed = 25)
{
Itemdbcaption [3]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_dlg_speed_250 );
}
Else if (pmonitorguiframe-> gsysmod. gmonitorconfig. recsweepspeed = 50)
{
Itemdbcaption [3]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_dlg_speed_500 );
}
Else // avoid pointer pointing to fly
{
Assert (false );
}

 

Switch (pmonitorguiframe-> gsysmod. gmonitorconfig. recrtmode)
{
Case 8:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_8s );
Break;
Case 16:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_16s );
Break;
Case 32:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_32s );
Break;
Case 120:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_continual );
Break;
Default:
Assert (false );
Break;
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.