locked
better way to swallow/ignore excpetion RRS feed

  • Question

  • How should i swallow the exception and continue the normal working?

    Tuesday, December 13, 2011 6:05 AM

Answers

  • That's kind of the rub - how can you be sure that you are able to continue normal processing?  The approach to swallow the exception is pretty simple.  Just include a catch block that does nothing.  My recommendation to you, though, would be to think carefully about the specific exception types that you expect to occur and know will not negatively impact your ability to continue processing and include catch blocks for those specific types of exception.  This will cause exceptions that you did not anticipate (and therefore cannot guarantee won't throw off your results) to bubble up.  An error message and even an application crash are almost always preferable to quietly giving your user the wrong answer because once the user discovers they were given a wrong answer your application will forever be viewed as untrustworthy.

    Tuesday, December 13, 2011 7:48 AM
  • It looks to me from the stack trace that the code is exception is being thrown from an event handler internal to the Telerik control and not necessarily from the code you're that you're executing.  In other words, it appears to be a side-effect but not necessarily within the flow of execution that contains your try/catch.  Telerik support folks have been VERY responsive to my inquiries in the past, so I would definitely recommend that you post on the Telerik support forum, but in the meantime maybe you could override the offending event handler to get by.

    Tuesday, December 13, 2011 9:06 AM

All replies

  • That's kind of the rub - how can you be sure that you are able to continue normal processing?  The approach to swallow the exception is pretty simple.  Just include a catch block that does nothing.  My recommendation to you, though, would be to think carefully about the specific exception types that you expect to occur and know will not negatively impact your ability to continue processing and include catch blocks for those specific types of exception.  This will cause exceptions that you did not anticipate (and therefore cannot guarantee won't throw off your results) to bubble up.  An error message and even an application crash are almost always preferable to quietly giving your user the wrong answer because once the user discovers they were given a wrong answer your application will forever be viewed as untrustworthy.

    Tuesday, December 13, 2011 7:48 AM
  • Thanks KyleMBurns, your are right.  But if it is coming from the third party controls how should i cater it. It may possible that this fault need to be fixed at their side and how can i fix that?

    i tried to swallow the exception but it is still raised

    try
    {
    
    }
    catch (Exception ex)
    {
    
    }
    
    ==================
    Or in this way.
    
    try
    {
    try
    {
     AddThirdPartyObject();
    }
    catch (Exception ex)
    {
    }
    }
    catch (Exception)
    {
    }
    Tuesday, December 13, 2011 8:09 AM
  • What exactly do you mean when you say it is still raised?  Try to be as detailed as you can in describing the behavior you're seeing and what you expect to see.

    Tuesday, December 13, 2011 8:17 AM
  • Hi KyleMBurns.

    I mean excpetion couldn't be suppressed after write try catch block as you and i mentioned in above post.

    I debugged my source and came to know that after performing all actions of that silverlight window (in which i wrote the try catch block  for suppressing exception). Execution flow simply moves from child window to app.xamls.cs .

    namespace NFS.UI.Silverlight
    {
        using System;
        using System.Runtime.Serialization;
        using System.ServiceModel.DomainServices.Client.ApplicationServices;
        using System.Windows;
        using System.Windows.Controls;
        using NFS.UI.Silverlight.Controls;
        using NFS.UI.Silverlight.ServiceClient;
        using System.Collections.ObjectModel;
    
        
        public partial class App : Application
        {
            private System.Windows.Controls.BusyIndicator busyIndicator;
    
         
            public App()
            {
                InitializeComponent();       
              
            }
    
            private void Application_Startup(object sender, StartupEventArgs e)
            {
                
                this.InitializeRootVisual();
            }
    
         
            private void Application_UserLoaded(LoadUserOperation operation)
            {
            }
            protected virtual void InitializeRootVisual()
            {
                this.busyIndicator = new System.Windows.Controls.BusyIndicator();
                this.busyIndicator.Content = new MasterPage();
                this.busyIndicator.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                this.busyIndicator.VerticalContentAlignment = VerticalAlignment.Stretch;
    
                this.RootVisual = this.busyIndicator;
            }
    
            static ErrorWindow _errorWin = null;
    
            private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
            {
                if (!System.Diagnostics.Debugger.IsAttached)
                {
    
                }
    
                e.Handled = true;
    
                if (_errorWin == null ||
                    (_errorWin.DialogResult.HasValue &&
                    _errorWin.DialogResult.Value))
                    _errorWin = ErrorWindow.CreateNew(e.ExceptionObject);
            }
        }
    }

       

    and at below line, it throws an exception

    _errorWin = ErrorWindow.CreateNew(e.ExceptionObject);

    and exception description is that

    Object reference not set to an instance of an object.

      at Telerik.Windows.Controls.GridView.GridViewCell.RaiseCellEditEndedEvent(GridViewEditAction editAction)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.PerformCellEditEnded(GridViewCell currentCell)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.CommitCellEdit(GridViewCell currentCell, Boolean isLeavingRow)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.CanCellBecomeCurrent(GridViewCell cell)
       at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)
       at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

    Tuesday, December 13, 2011 8:48 AM
  • It looks to me from the stack trace that the code is exception is being thrown from an event handler internal to the Telerik control and not necessarily from the code you're that you're executing.  In other words, it appears to be a side-effect but not necessarily within the flow of execution that contains your try/catch.  Telerik support folks have been VERY responsive to my inquiries in the past, so I would definitely recommend that you post on the Telerik support forum, but in the meantime maybe you could override the offending event handler to get by.

    Tuesday, December 13, 2011 9:06 AM
  • Yes exactly. I have logged many posts there but unfortunately none of them would be replied.  

    Thanks KyleMBurns.

    Tuesday, December 13, 2011 9:13 AM