0

I'm writing a windows application. I have media player in my form. When I set the URL to something like "fsgfbnhgb" (something wrong!) the player by itself shows an error. But it's not good. I have "try" and "catch" blocks and in try block there isn't any exceptions when URL is "fgdsfgasgfas"! Because the player by itself catches the exception. How can I set error for media player by myself?

try
{
  player.URL = "fdgsdgsdg";
  player.Ctlcontrols.play();
}
catch
{
  snd.Play();
  MessageBox.Show("An error occurred during reading the alarm music path. Check that its directory is valid.", "Alarm music error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Thank you all

Marco Leogrande
  • 8,050
  • 4
  • 30
  • 48
Emran
  • 544
  • 7
  • 26

1 Answers1

0

You could try checking if the file exists first, inside the try{} catch{}

try{
    string url = "sdahgjk";
   if (!File.Exists(url))
        throw new Exception("Exception Message Here");
   player.Url = url;
   player.Ctlcontrols.play();
        }
        catch
        {
            snd.Play();
            MessageBox.Show("An error occurred during reading the alarm music path. Check that its directory is valid.", "Alarm music error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
S Grimminck
  • 516
  • 4
  • 21