AnsweredAssumed Answered

try catch inside .c and .cpp files

Question asked by MikeSmithCanada on Jul 25, 2013
Latest reply on Jul 30, 2013 by MurrayA

If try and catch are syntax error inside .c files

void C_FunctionInsideCfile(void) {

        try {

            printf("Inside tryC\n");

            throw 6;

        }

         catch (int * error) { }

}

 

Should they also be syntax errors inside an extern "C" function inside a C++ file,

and if not -- what is actually behaviour on exception -- as C function inside C file throwing exceptions normally hunt up the stack for the next catch in some C++ function earilier executed

 

#include <stdio.h>

#include <iostream>

using namespace std;

 

void CPP_Function( void) {

    int error;

        try {

            printf("Inside tryCPP\n");

            throw 6;

        }

        catch (int * error) { }

}

 

extern "C" void C_FunctionInsideCPPFile(void) {

        try {

            printf("Inside tryC\n");

            throw 6;

        }

        catch (int * error) { }

}

 

 

This example arose as I had to throw a exception inside an assembly file in VDSP so I wrote the throw inside a C++ file and I knew the name-mangling in VDSP to get to the C++ function

 

Since I do not yet understand CCES namemangling I just use extern "C" in front of the function

 

I was getting unexplained behaviour so I did this to get around the problem

 

 

void ExtraStep(void) {

        try {

            printf("Inside tryC\n");

            throw 6;

        }

        catch (int * error) { }

}

 

extern "C" void C_FunctionInsideCPPFile(void) {

     ExtraStep( );

}

Outcomes