media player exceptions
-
30-06-2021 - |
Question
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
Solution
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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow