0

It seems you can not use Await to show error message in Try-Catch Statement:


MessageDialog mError = new MessageDialog("Error: You entered: " +  txtNbr.text , "Not a Number");
await mError.ShowAsync();

How to show error message in Try-Catch Block ??

Thanks

------- Update
I got error for this " Unspecific Error "


public async void Populate()
        {

            try
            {

                string PrintText = "";

                //--- Create a Run of plain text and some bold text.
                Windows.UI.Xaml.Documents.Run myRun1 = new Run();
                myRun1.Text = "testing testing testing  \n  1213131313 \n";
                P1.Inlines.Add(myRun1);
                textContent.Blocks.Add(P1);

            }
            catch (Exception ex)
            {

                ErrorMessage = ex.Message;

            }

            if (ErrorMessage != "")
            {
                MessageDialog mError = new MessageDialog(ErrorMessage, "Error");
                await mError.ShowAsync();
                ErrorMessage = "";
            } 

        }





MilkBottle
  • 4,242
  • 13
  • 64
  • 146

1 Answers1

0

From MSDN: "An await expression can't occur in a catch block or a finally block."

You could restructure your code to set a flag in the catch block and show the message dialog outside of the catch block if the flag is set.

Nathan Kuchta
  • 13,482
  • 2
  • 26
  • 35