locked
How should I deal with these Exception?

    Question

  • When I read "Creating Asynchronous Operations in C++ for Windows Store Apps"(http://msdn.microsoft.com/en-us/library/windows/apps/hh750082.aspx), I input these code, and I caught next exceptions.

    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::details::_Interruption_exception at memory location 0x0703F6E0.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::details::_Interruption_exception at memory location 0x0703F6D4.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::details::_Interruption_exception at memory location 0x06F3E22C.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::details::_Interruption_exception at memory location 0x0713F618.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::details::_Interruption_exception at memory location 0x0713F60C.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::details::_Interruption_exception at memory location 0x06F3E220.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::details::_Interruption_exception at memory location 0x06F3E844.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::task_canceled at memory location 0x0703EEF0.
    First-chance exception at 0x748F277C in TaskUsage2.exe: Microsoft C++ exception: Concurrency::task_canceled at memory location 0x023EC168.

    But , How should I deal with these exception.

    And next is my  test code:

    void MainPage::IAsyncActionOperationWithProgress_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	m_asyncOpWithProgress = m_primesTest->GetPrimesWithProgressAsync(0, 100000);
    	
    	OutputDebugString(TEXT("Before IAsyncOperationWithProgress\n"));
    
    	m_asyncOpWithProgress->Progress = ref new AsyncOperationProgressHandler<IVector<int>^, double>(
    		[this](Windows::Foundation::IAsyncOperationWithProgress<IVector<int>^, double>^ asyncInfo, double percent)
    	{
    		LogPrint(TEXT("Callback: %f\n"), percent);
    	}, Platform::CallbackContext::Same);
    
    	OutputDebugString(TEXT("Middle IAsyncOperationWithProgress\n"));
    
    	create_task(m_asyncOpWithProgress).then([](task<IVector<int>^> task1)
    	{
    		try
    		{
    			IVector<int>^ intArray = task1.get();
    			for (int i=0; i < intArray->Size; i++) {
    				int nValue = intArray->GetAt(i);
    				LogPrint(TEXT("Primes: %d\n"), nValue);
    			}
    		} catch (task_canceled&) {
    			LogPrint(TEXT("Task_Canceled Time: %I64u\n"), GetTickCount64());
    		} catch(Exception^ e) {
    			LogPrint(TEXT("Exception Time: %I64u\n"), GetTickCount64());
    		}
    	});
    
    	OutputDebugString(TEXT("After IAsyncOperationWithProgress\n"));
    }
    
    void MainPage::Cancel_AAOWP_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	LogPrint(TEXT("Before Cancel Time: %I64u\n"), GetTickCount64());
    	m_asyncOpWithProgress->Cancel();
    	LogPrint(TEXT("After Cancel Time: %I64u\n"), GetTickCount64());
    }

    IAsyncOperationWithProgress<IVector<int>^, double>^ 
    	Primes::GetPrimesWithProgressAsync(int first, int last)
    {
    	return create_async([this, first, last](progress_reporter<double> reporter) -> IVector<int>^
    	{
    		// Ensure that the input values are in range.
    		if (first < 0 || last < 0) {
    			throw ref new InvalidArgumentException();
    		}
    
    		// Perform the computation in parallel.
    		concurrent_vector<int> primes;
    		long operation = 0;
    		long range = last - first + 1;
    		double lastPercent = 0.0;
    		parallel_for(first, last + 1, [&primes, &operation, range, &lastPercent, reporter](int n)
    		{
    			if (is_task_cancellation_requested()) {
    				OutputDebugString(TEXT("Exception cancel task\n"));
    				cancel_current_task();
    			}
    
    			// Report progress message.
    			double progress = 100.0 * InterlockedIncrement(&operation) / range;
    			if (progress >= lastPercent)
    			{
    				reporter.report(progress);
    				lastPercent += 1.0;
    			}
    
    			// If the value is prime, add it to the local vector.
    			if (is_prime(n)) {
    				primes.push_back(n);
    			}
    		});
    		reporter.report(100.0);
    
    		// Sort the results.
    		sort(begin(primes), end(primes), less<int>());
    
    		// Copy the results to an IVector object. The IVector
    		// interface makes collections of data available to other
    		// Windows Runtime components.
    		IVector<int>^ results = ref new Vector<int>();
    		for_each(begin(primes), end(primes), [&results](int prime) {
    			results->Append(prime);
    		});
    
    		return results;
    	});
    }
    

    Tuesday, November 13, 2012 6:19 AM

Answers

  • I'm assuming from what you're showing that you're only seeing these as first chance exceptions in the debugger and not unhandled exceptions.  That's normal; these are mostly not things you need to "deal with".  Concurrency::details::_Interruption_exception is an internal exception which is thrown and caught by the PPL as part of the way it unwinds the stack during cancellation of parallel operations.  It will flow through your code (in particular your parallel_for), but it isn't something you should ever explicitly throw or catch.

    You are already handling the task_canceled which you see.  Your continuation off m_asyncOpWithProgress calls get on the antecedent (task1.get()).  When the antecedent has been canceled, calling this will result in a throw of task_canceled which your code is dealing with by doing a LogPrint right now.  How you deal with the fact that some operation was canceled is app specific.

    Let me know if this doesn't answer your question.

    Friday, November 16, 2012 6:44 PM

All replies

  • Hi,

    Maybe you can follow this blog to analyze this exception.
    http://blogs.msdn.com/b/win8devsupport/archive/2012/10/26/how-to-debug-a-task-exception-in-windows-store-application.aSpx

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 14, 2012 7:51 AM
  • I'm assuming from what you're showing that you're only seeing these as first chance exceptions in the debugger and not unhandled exceptions.  That's normal; these are mostly not things you need to "deal with".  Concurrency::details::_Interruption_exception is an internal exception which is thrown and caught by the PPL as part of the way it unwinds the stack during cancellation of parallel operations.  It will flow through your code (in particular your parallel_for), but it isn't something you should ever explicitly throw or catch.

    You are already handling the task_canceled which you see.  Your continuation off m_asyncOpWithProgress calls get on the antecedent (task1.get()).  When the antecedent has been canceled, calling this will result in a throw of task_canceled which your code is dealing with by doing a LogPrint right now.  How you deal with the fact that some operation was canceled is app specific.

    Let me know if this doesn't answer your question.

    Friday, November 16, 2012 6:44 PM