Viva64 Send comments on this topic.
V116. Memsize type used for catch

Glossary Item Box

The analyzer found a possible error related to the use of memsize type for catching exception. The error may consist in the incorrect exception handling.

Let’s examine an example of the code which contains throw and catch operators.

  Copy image Copy Code
try {
    try {
      throw UINT64(-1);
    }
    catch(size_t) {
      cout << "x64 portability issues" << endl;
    }
  }
  catch(UINT64) {
      cout << "OK" << endl;
  }


The work result on the 32-bit system: OK The work result on the 64-bit system: x64 portability issues

This behavior change is connected with what on 64-bit system the size_t type is equivalent to UINT64.

Correction of the described situation consists in change of a code for achievement of necessary logic of work.

More right correction will consist in refusal of similar practice of programming. We recommend using special classes for sending information about the error.

See also:

memsize type

V115. Memsize type used for throw