.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

ExceptionValidationRule not catching IValueConverter exceptions

Posted By:      Posted Date: October 18, 2010    Points: 0   Category :WPF


I've read that adding an ExceptionValidationRule to a control "catches exceptions that occur at any point, including exceptions that occur if the edited value can't be cast to the correct data type, exceptions that are thrown by the property setter, and exceptions that are thrown by the value converter ". So I've set one up to be used in conjunction with my value converter but when my value converter throws an exception, it's not being handled. My book is for WPF 3.0 so has something changed, or am I doing something wrong? Here is my code:



public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  System.Text.RegularExpressions.Regex nonDigits = new System.Text.RegularExpressions.Regex(@"[^\d]+");
  string phoneNum = nonDigits.Replace((string)value, String.Empty);

  if (phoneNum.Length != 10)
    throw new ArgumentEx

View Complete Post

More Related Resource Links

How to get more information about the exceptions that can happen in SharePoint 2010 projects?

In case there is an exception anywhere in the SharePoint 2010 project (most common place an exception would happen is during deployment of your SharePoint project, custom deployment configuration or custom deployment steps), there's a registry key EnableDiagnostics available for you to use.

Handling external C++ exceptions


Hi. I'm working in a application that uses an external .Dll developed in C++ language. According the business rule, the .Dll can throws one exception if it found a error. My question is if it's possible handle or catch a exception throwed by the C++ dll? The try/catch doesn't works. Bellow there's the code I'm using to call the C++ dll.

        public extern static IntPtr LoadLibrary(string lpLibFileName);

        [DllImport("kernel32", CharSet = CharSet.Ansi)]
        public extern static IntPtr GetProcAddress(IntPtr hLibModule, string procName);

        public extern static bool FreeLibrary(IntPtr hLibModule);

        private delegate void DllMethodCallBack(string param1, string param2);

        public void CallDllMethod(string param1, string param2)

.NET Matters: Aggregating Exceptions


Exceptions in .NET are the fundamental mechanism by which errors and other exceptional conditions are communicated. This month's column provides information about how to aggregate exceptions to help manage a variety of scenarios in which multiple exceptions might result from one operation, including scenarios involving parallelism and concurrency.

Stephen Toub

MSDN Magazine August 2009

CLR Inside Out: Handling Corrupted State Exceptions


There's a danger in using one-size-fits-all exception handling, and you need to know how to avoid it by being as specific as possible about how you handle errors.

Andrew Pardoe

MSDN Magazine February 2009

Bugslayer: Minidumps for Specific Exceptions


This installment of Bugslayer covers the use of ADPlus to create a minidump of your Microsoft .NET Framework 2.0 pro¬cesses on specific exceptions.

John Robbins

MSDN Magazine November 2006

Bugslayer: Unhandled Exceptions and Tracing in the .NET Framework 2.0


By now, you've certainly heard about the big changes coming in Visual Studio® 2005, but when it's time to move your code over it will be the small things that trip you up. In this column, I want to cover two of the many excellent changes that you could easily overlook as you make the move to the new runtime and development tools.

John Robbins

MSDN Magazine July 2005

ADO.NET: Tackle Data Concurrency Exceptions Using the DataSet Object


ADO.NET provides many techniques for improving the performance of data-intensive applications and for making them easier to build. The DataSet, the hallmark of the ADO.NET object model, serves as a miniature, disconnected facsimile of a data source. While using the DataSet improves performance by reducing expensive trips to the database server, it also introduces the possibility of multiple users attempting to change the same data simultaneously, thereby generating data concurrency exceptions. This article examines the common causes behind data concurrency exceptions and presents techniques for overcoming them.

David Burgett

MSDN Magazine April 2003

.NET Exceptions: Make the Transition from Traditional Visual Basic Error Handling to the Object-Orie


If you're used to Visual Basic 6.0 and you're making the transition to Microsoft .NET, you will find that error handling is quite different from what you've used for years. Visual Basic .NET uses a more object-oriented solution to signaling and responding to unexpected problems while your program is running. This approach, called structured exception handling, has a number of advantages over the On Error statements provided in previous versions of Visual Basic. For instance, exceptions give you lots more information about exactly what went wrong in your app. To help you take advantage of this modern error handling paradigm, this article will show you how to raise and respond to exceptions, as well as how to create your own custom exception classes.

Jesse Liberty

MSDN Magazine November 2002

Html Helpers and Exceptions



I have been working in a few MVC HTML Helpers. For example:

    public static MvcHtmlString GoogleAnalytics(this HtmlHelper helper, String account, String url) {
      // ...

If account or url are null should I trhow an exception? Or render an empty string? Or render an Html comment in the view?

What is the recommended approach for this?



.NET4, DataGrid doesn't apply EditingElementStyle with ValidatesOnExceptions when catching an excep

Hello everyone, I'm using WPF and the .NET 4 framework (4.3.30319), on the Windows 7 32-bit OS. I wanted to keep things simple with validation and my property setter just throws an ArgumentException when the data is not valid, instead of implementing a ValidationRule class. While this worked with a ListBox, it seems it doesn't with a DataGrid. Below is a simple example to reproduce the problem, check the XAML and C# code related to the 2nd column. The datagridTBStyle is meant to apply a specific style when an error occurs (since control templates are out of the question with DataGrid), but what I see is: it applies the correct style when editing the cell (blue text) it doesn't apply the part that is supposed to trigger on Validation.HasError (red on yellow background + tooltip) Without this style, it doesn't apply a red border around the cell as it should according to the documentation. However, it does put a part of red exclamation mark in the row header when an error occurs, and it catches the exception. Am I doing something wrong, or is this actually a bug? Link to the documentation. <Window x:Class="DataGridTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Test" Height="200" Width="350&q

Shielding Exceptions at WCF Service Boundaries using Microsoft Enterprise Library 4.1

To enable the exception shielding feature in my WCF service I have done the following steps Added references of the following assemblies: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.ObjectBuilder2.dll Added a Using statement for Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF. Added the ExceptionShielding attribute to a service implementation class and specified the name of the exception policy to use as a constructor parameter. Add the Exception Handling Application Block configuration sections to the service's Web.config file. <add name="WCFServicePropogate">         <exceptionTypes>           <add type="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"             postHandlingAction="ThrowNewException" name="Exception">             <exceptionHandlers>               <add exceptionMessage="I created the exception" faultContractType=

Report Model/Report Builder/Out of Memory Exceptions

We are getting out of memory exceptions on our server. We are using Report Builder against a Report Model in RS2008. Here is part of the errors we are getting. I cannot find any information for an error 200. Here is part of the error log:   processing!ReportServer_0-2!17d8!08/25/2010-10:07:29:: e ERROR: Throwing Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: An unexpected error occurred in Report Processing., ;  Info: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: An unexpected error occurred in Report Processing. ---> System.TypeInitializationException: The type initializer for 'Microsoft.ReportingServices.ReportIntermediateFormat.Sorting' threw an exception. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.    at Microsoft.ReportingServices.ReportIntermediateFormat.Sorting..cctor()    --- End of inner exception stack trace ---    at Microsoft.ReportingServices.ReportIntermediateFormat.Sorting..ctor(ConstructionPhase phase)    at Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ProcessingRIFObjectCreator.CreateRIFObject(ObjectType objectType, IntermediateFormatReader& context)    at Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.IntermediateFormatReader.ReadRIFObject(Boolean ve

BUG: Exceptions propagation behaviour is different if the application is run inside visual studio.

I'm going crazy. I have a simple application: one form, one module. The project is configured to start from sub main. The module contains: Module Module1 Public Sub main() Try Application.Run(New Form1) Catch ex As Exception MessageBox.Show(ex.Message, "Fatal Error") End Try End Sub End Module Form1 contains one button and one event: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Throw New Exception("operation aborted") End Sub End Class I run the application inside visual studio... A new instance of Form1 is shown. I click the button. The exception is propagated to the sub main and the messagebox is shown. RIGHT!... I close visual studio (without recompiling anything) and I run the SAME .exe that was generated before... A new instance of Form1 is shown. I click the button. The exception IS NOT propagated to the main sub and a dialog appears: System.Exception: operation aborted in textexception.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Lino Barreca\Documenti\Visual Studio 2008\Projects\textexception\textexception\Form1.vb:riga 4 in System.Windows.Forms.Control.OnClick(EventArgs e) in System.Windows.Forms.Button.OnClick(EventArgs e) in System.Windows.Forms.ButtonBase.OnKeyUp(KeyEventArgs kevent)

Catching offline website?

Hi! I have an intranet where we display the 5 latest news article headlines from the BBC. The problem I am having just now is if the BBC website or their XML feed is formatted incorrectly it takes our intranet offline, throwing up a ASP.net error screen. What I would prefer it to do is to post a message saying BBC Feed currently offline. protected void Page_Load(object sender, EventArgs e) { //SPECIAL Message AREA SqlConnection connMsg; string cs = ConfigurationManager.ConnectionStrings["SpecialConnectionString"].ConnectionString; connMsg = new SqlConnection(cs); connMsg.Open(); SqlCommand msgCOM; msgCOM = new SqlCommand("SELECT * FROM [msg_table] ORDER BY [msg_id] Desc", connMsg); SqlDataReader DRMsg = msgCOM.ExecuteReader(); if (DRMsg.HasRows) { while (DRMsg.Read()) { DateTime varDate = Convert.ToDateTime(DRMsg["msg_date"]); string varContMessage = Convert.ToString(DRMsg["msg_content"]); Literal LiteralMessage = new Literal(); LiteralMessage.Text = "<div class=\"specialMessageDate\">"+ varDate.ToString("g") + "</div><strong>" + varContMessage + "</strong><br /><br />&

Try-Catch block cannot handle exceptions when contacting a Silverlight Client using net.tcp Duplex W

I have created a simple duplex WCF for Silverlight 4 clients, using net.tcp binding (.NET Framework 4.0)  The client interface is declared as <ServiceContract()> _ Public Interface IServiceClient <OperationContract(IsOneWay:=True)> _ Sub SendUpdate(ByVal allRecords As List(Of String)) End Interface while the service interface is declared as <ServiceContract(Namespace:="SilverlightService", CallbackContract:=GetType(IServiceClient))> _ Public Interface IService <OperationContract(IsOneWay:=True)> _ Sub Connect() End Interface The service code is implemented like: <ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Multiple, InstanceContextMode:=InstanceContextMode.Single)> _ <Activation.AspNetCompatibilityRequirementsAttribute(RequirementsMode:=Activation.AspNetCompatibilityRequirementsMode.Allowed)> _ Public Class Service Implements IService 'Keep the list of all the active/connected clients: Public _clients As List(Of IServiceClient) = New List(Of ITrackServiceClient) Public Sub Connect() Implements IService.Connect Dim client = OperationContext.Current.GetCallbackChannel(Of IServiceClient)() Dim clientExist = From p In _clients _ Where p Is client _ Select p If clientExist.Count() = 0 Then Monitor.Enter(_clients) _clients.Add(client) Monitor.E

XCOPY deployment of WCF application produces random exceptions

We are using a simple self-developed XCOPY-like tool for copying the binaries etc. of a WCF application directly into the physical folder of a virtual directory on IIS. After the deployment the application randomly throws an excetion ("The ObjectContext instance has been disposed and can no longer be used for operations that require a connection"). I know that this is EF related (we are using EF for data access purposes within our WCF services) but donÄt think it has anything to do with EF.However, the exception occurs absolutely without any pattern. Starting our app multiple times results in the excetion sometimes but it succeeds immediately afterwards. I even restarted the IIS windows service but the same phenomenon still exists afterwards.When I use the "Publish" dialog from VS2008 for the deployment everything is fine. However, we need to do the deployment through our script as we have a staging location between our dev and prod environments.What do we have to to in order to make a successfull and reliable XCOPY deployment and get rid of this strange behaviour?

VB6 Conversion to VB.net Wrapper to prevent Null Exceptions

Thanks for reading this. We are converting a large VB6 application to VB.net. The problem we have all over the code is the .NET converter did not "reorder" the "IF" and other statements in the code to stop execution when a DBNull value exists.  For example, we have code like this all over the place. "If rRow.Item("av_election_id") > 0 And (rRow.Item("Challenged") <> "SUSPD" Or IsDBNull(rRow.Item("Challenged"))) Then" This causes a error when "rRow.Item("Challenged") is dbnull The line of code below corrects this issue but we have thousands of lines of code to reorder and refactor.  If   dtAVVoterRow.Rows(0)("av_election_id") > 0 And (IsDBNull(dtAVVoterRow.Rows(0)("Challenged")) OrElse dtAVVoterRow.Rows(0)("Challenged") <> "SUSPD") Then My question is does anyone have any idea of creating a wrapper class or something to allow us to keep the first example of code above where it will not throw an error when encountering a Null value?  I don't know if a wrapper that reordered the If statements, or captures the error but continues the execution somehow? I appreciate any help.  THanks!  
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend