Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:55:27+00:00 2026-06-18T05:55:27+00:00

How does one catch I/O exceptions on windows phone 8, c++/cx? EDIT: Here’s a

  • 0

How does one catch I/O exceptions on windows phone 8, c++/cx?

EDIT: Here’s a full example

Checking to see if a file “hello.txt” exist:

StorageFile^ Testme(String^ fileName)
{
    StorageFolder^ item =  ApplicationData::Current->LocalFolder; 
    try
    { 
        task<StorageFile^> getFileTask(item->GetFileAsync("hello.txt")); 
        getFileTask.then([](StorageFile^ storageFile)
        { 
           return storageFile;
         }); 
     }
     catch (Exception^ ex)
     {
        OutputDebugString(L"Caught the exception");
     }
     return nullptr;
}

If “hello.txt” exsit, method Testme returns the file ptr like a charm.
If “hello.txt does not exist, not only does it not throw exception FileNOtFound, instead I go crashing with this showing up in the debugger window:

Unhandled exception at 0x71D49C01 (Msvcr110d.dll) in MyPhoneApp.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.
If there is a handler for this exception, the program may be safely continued

What’s wrong and how would I elegantly check if a file exist’s or not in WP8?

I really hope someone answers … Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:55:28+00:00Added an answer on June 18, 2026 at 5:55 am

    After spending hours to figure out what the problem was in a related issue, I finally figured it out. Using C++, it looks Visual Studio behaves a little interesting. Instead of passing the exception to the user, it just throws it. That means even if you had a handler for the exception, your handler was not allowed to handle it. I should note here that this only happens when you run your App inside Visual Studio. Deploying and launching app shows no problem.

    So to resolve it, open the exceptions settings (from Menu > Debug > Exceptions – or Ctrl+D, E). Enlarge “C++ Exceptions” and deselect “Platform::InvalidArgumentException” in “Thrown” column. Then you should be good to go.

    Update after first comment:

    First of all, I had to deselect COMException from the list too for below example to work.

    In addition to doing above. It is important to understand async programming in C++/CX. You can not simply return from the function after creating the task. If you really need to return you need to return the worker task you created to do the job. Below is a Windows Store app sample (not WP) but they should work the same. Your helper function must be like below.

    concurrency::task<bool> TestFileExists::MainPage::Testme(String^ fileName)
    {
        using namespace Windows::Storage;
        using namespace concurrency;
    
        StorageFolder^ item =  ApplicationData::Current->LocalFolder; 
    
        return create_task(item->GetFileAsync(fileName)).then([this](task<StorageFile^> t)
        {
                bool fileExists = true;
    
                try {
                        StorageFile^ file = t.get();
                }
                catch(Platform::Exception^ exp)
                {
                        fileExists = false;
                }
    
                return (fileExists);
        });
    }
    

    And you should call it like below.

    Testme("hello.txt").then([this](concurrency::task<bool> t)
    {
        auto dispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
    
        // dispatch the task of updating the UI to the UI task not to run into exception
        dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal,
            ref new Windows::UI::Core::DispatchedHandler(
            [=]()
        {
            bool exists = t.get();
    
            if (exists)
            {
                txtbFileExists->Text = L"File is there";
            }
            else
            {
                txtbFileExists->Text = L"File is NOT there";
            }
    
        }));
    
    });
    

    I do not know where local folder is so I could not test the condition in which the file is actually there. Please test and see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one use rm to delete a file named '--help'? When I try,
Here's my hypothetical example. I have a very simple WPF window with a one
does one perform better over the other in terms of indexing/quering etc ? e.g.
How does one wait until all of the Javascript is loaded before curling a
How does one implement a multithreaded single process model in linux fedora under c
How does one write a (Intel) F90 function that converts a string into lowercase
How does one optimize if the parameter space is only integers (or is otherwise
How does one determine what is the trigger of an event (close browser, close
How does one alternate row colors in a table in django that's generated using
How does one revert a remote git repo after a reset done locally? We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.