A Normal function ( say printArray) takes array and its size ( 2 arguments ) to print elements of an array.
How to do the same using exceptions? More exactly, how to pass array size to catch handler ? ( assuming I dont have a const int SIZE declared outside try-catch) eg.
 //void printArray(int* foo ,int size);
     int foo[] = { 16, 2, 77, 40, 12071 };
   //printArray(foo,5); //OK, function call using array accepts size=5 
    try{
        //do something
        throw foo;
    }
    catch (int* pa)
    {
        //I have to get array size to loop through and print array values
        //    How to get array size?
    }
Thank you in advance
You can throw both array and it's size as a pair in the following way:
throw std::make_pair(foo, 5);
and get these two values like this:
catch(std::pair<int*, int>& ex)
{
...
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With