Why does Treelist DevExpress regularly throw HideException?

I worked with DevExpress Filter TreeList and I wonder why it threw DevExpress.Utils.HideException .

My understanding is that exceptions are expensive and should be used sparingly and only in certain situations, but the code snippet below shows that we always throw a HideException without any specific events or triggered code.

From FilterTreeList.cs

 private void OnMouseDown(object sender, MouseEventArgs e) { if ( e.Button != MouseButtons.Left ) return; TreeListHitInfo hitInfo = ((TreeList)sender).CalcHitInfo(e.Location); if ( hitInfo.HitInfoType == HitInfoType.Column ) { ColumnInfo colInfo = ((TreeList)sender).ViewInfo.ColumnsInfo[hitInfo.Column]; GridFilterButtonInfoArgs filterButtonInfo = GetFilterButtonInfoArgs(colInfo); if ( filterButtonInfo != null && filterButtonInfo.Bounds.Contains(e.Location) ) { filterButtonInfo.State = ObjectState.Pressed; ((TreeList)sender).InvalidateColumnHeader(hitInfo.Column); throw new HideException(); } } 

Why are they throwing a HideException here and what is the use of it?

+4
source share
3 answers

This is a program flow engine to clean up the management environment. Although it is true that exceptions are expensive compared to regular code (an archetypal example uses FormatExceptions in a loop that converts strings to ints - hence the need for methods like TryParse), compared to major changes in the user interface, retrieving data from the database and etc., they are very cheap and easy to maintain.

The demo code you are quoting is the exact scenario: the control is about to update all content. The end user clicked on a specific icon to perform a specific action - the exception is not always always. My only beef with this sample code (and I emphasize that this is sample code) is that the action is performed with the mouse down, not under the mouse.

I suggest that the argument "can exceptions be used for this kind of macro thread, or should we establish a rule of hard and fast that they should only be used for error reporting?" But this is another question.

Update

The WinForms team told me:

HideException is our internal exception, which is used to prevent the processing of mouse events by default. We agree with this old-fashioned way to stop code execution, especially considering that we already have DXMouseEventArgs with the option to set e.Handled = true . Unfortunately, XtraTreeList does not currently fully support DXMouseEventArgs . We will add this functionality to the next minor version and update the E2474 example accordingly.

So, it will be archaeological interest in a month or so.

+7
source

I would say that this

  • Error
  • Used for a message signaling a call to Response.Redirect will throw a ThreadAbort exception to stop the execution of all code.
+1
source

It seems to me that they use exceptions to control program flow. Some notes in the documents do not allow the base class method to receive a call. This is very terrible. The .NET framework's way to do this without exception is the HandledMouseEventArgs class used by OnMouseWheel ().

+1
source

All Articles