Click here to Skip to main content
15,885,887 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am using the c# wrapper for libvlc wich displays the media files in the player as required.
I need to catch any error that occurs while playing the media file(vlc related error).
Posted

1 solution

First of all, you need to catch all exception which may be thrown inside the main event loop of the UI thread.

First, you need to get Application.ThreadException triggered so don't forget this (in Main()):

C#
Application.SetUnhandledExceptionMode(
    UnhandledExceptionMode.CatchException);


ThreadException handler should be set up like this:

C#
Application.ThreadException += (sender, args) => {
    MessageBox.Show(string.Format(
            "{0}:\n\n{1}", args.Exception.GetType().Name, 
            args.Exception.Message),
        string.Format(
            " {0}: Error", ProductName),
        MessageBoxButtons.OK, MessageBoxIcon.Error);
}; //ThreadException


If you have other threads, you generally need to catch all exceptions on the very top stack frame of each thread.

This is the very basic level of exception handling in a Form application. Other cases are semantic, you should know better where to catch them. Many beginners catch too much, blocking propagation of exceptions, which is very bad. There are very few cases when blocking of exception propagation is acceptable or needed. You don't need to catch exceptions where the are thrown, you need to catch them in the frame where you know exactly how can you fix the effect of exception, in all other cases just let them go.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900