IBM Support

IV68564: EXCEPTION THROWN IN DESTRUCTOR NOT CAUGHT

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • An exception thrown in an object destructor is not being caught
    inside the destructor even though it has a try/catch statement.
    
    Instead, the exception is cascaded back to a parent try/catch.
    The issue may be related to scoping around the object
    construction/destruction, as well as the inheritance structure
    of the class.
    
    
       === TEST CASE ===
    
    #include <stdio.h>
    
    struct Parent
    {
     ~Parent() {}
    };
    
    struct Child : Parent
    {
     typedef void (*func_ptr)();
     func_ptr passed_function;
    
     Child(func_ptr func) : passed_function(func) {}
    
     ~Child()
     {
      try { passed_function(); }
      catch (...) {}
     }
    };
    
    void my_exception_function()
    {
     throw 1;
    }
    
    int main(int, char*[])
    {
     try
     {
      {
       Child test(my_exception_function);
       printf("Test scope exception:  ");
      }
    
      printf("Good\n");
     }
     catch (...) { printf("Bad\n"); }
     return 0;
    }
    
    
    $ xlC test.cpp
    $ ./a.out
    Test scope exception:  Bad
    $
    

Local fix

  • Modifications to the code may work around the issue:
    
    - make the destructor in the base class virtual
    - remove the base class destructor
    - remove the inheritance
    - remove the destructor declaration from the base class
    

Problem summary

  • PROBLEM DESCRIPTION:
    Due to the extra lexical block in the try{} code, the compiler
    was not able to correctly determine the scope in which the
    destructors needed to be called.
    
    USERS AFFECTED:
    Users with nested exception handling with extra lexical block
    scope requiring destructors.
    

Problem conclusion

  • A fix has been made to circumvent the issue.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV68564

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    D10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2015-01-15

  • Closed date

    2015-04-29

  • Last modified date

    2015-04-29

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL C/C++ FOR AI

  • Fixed component ID

    5725C7200

Applicable component levels

[{"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"13.1","Edition":"","Line of Business":{"code":"LOB73","label":"Power TPS"}}]

Document Information

Modified date:
19 August 2024