Some people are looking for direct answer and some people
doesn't care at all but needs an answer.
Today, I'll make straight points discussing WPF Exceptions.
The list below are the basic way to catch or look an exception.
1. Try..Catch..Finally block.
2. Using the Application.DispatcherUnhandledException
3. looking at Silent exceptions.
1. Try..Catch..Finaly block still the most commonly used to catch almost all types of errors during run-time.
this statement is very easy to use... for example
string a = null;
try
{
if (a == null) throw new NullReferenceException();
}
catch (NullReferenceException e)
{
//exception 1
}
catch (FieldAccessException fex)
{
//exception 2.......
}
finally
{
//finally block executed with or without error....
}
NOTE : If you are concerned about performance, I don't suggest that you use "try.. catch.." block.. this will swallow the exception and can possibly don't throw your exception to your UI level.
In this section I will not discuss handling this kind of exception in Multi-threading.
2. Using the application level to catch exception thrown by any of your code is the most simple and yet effective type of catching error. To do this in WPF, you write your code in the Application.Xaml code behind. On Application.xaml.vb (cs), type your custom handler on the Application_DispatcherUnhandledException() method. This can catch your exception. voila...
You can now have your exception handler without worrying other developers cathing
exception.
3. The last exception that I will be pointing out are those silent exceptions, silent exceptions
mostly don't interact with your UI thread level. If you are running your application inside
your Visual Studio, you can actually locate them at the Output Window. Most of these exceptions
are caused sometimes by WPF databinding. Using MVVM actually cannot detect binding errors
at design time so be careful.
Silent Exceptions also has performance penalty if you don't handle them. So, you better
check and clear these kind of exceptions in your apps.
Make it simple. The key to handle these exceptions.
Enjoy. GTG. Thinking other things for my ASP.NET project.
No comments:
Post a Comment