Fork me on GitHub
The journal that this archive was targeting has been deleted. Please update your configuration.
« Report a Message using a ViewModel | Main | Define Behavior Context Objects »

Catch and Report Behavior Exceptions

All Behaviors execution are isolated piece of methods that are wrapped with a Behavior class. The behaviors have no knowledge of how to report errors and they would just propagate the error (Exception) to the caller up the stack. Now, we want to catch errors whenever a behavior is executed and report it back to the user. To catch exceptions you would override OnBehaviorEvent from the controller and wrap it with a try..catch statement like this:
public partial class Controller
        // override OnBehaviorEvent from the Controller class
    protected override void OnBehaviorEvent<T>(
        IExecutableBehavior<T> executableBehavior, 
        BehaviorEvent<T> behaviorEvent)
             executableBehavior, behaviorEvent);
        catch(Exception ex)
            // handle your exception here, in this case
            //..I am using Telerik RadToolTip to display messages
            //..for more information how to use RadToolTip visit: 
            this.RadToolTipMessage.Text = ex.Message;
            this.RadToolTipMessage.Title = "Error";
            this.RadToolTipMessage.Visible = true;
            this.RadToolTipMessage.Animation = ToolTipAnimation.Fade;

    //..Initialize my RadToolTip
    protected override void OnInit(EventArgs e)
        this.RadToolTipMessage = new RadToolTip()
            ID = "RadToolTipMessage",
            Skin = "Metro",
            VisibleOnPageLoad = true,
            RelativeTo = ToolTipRelativeDisplay.BrowserWindow,
            Visible = false,
            Position = ToolTipPosition.Center,
            HideEvent = ToolTipHideEvent.ManualClose,
            ShowDelay = 15000,
            AutoCloseDelay = 10000,
            HideDelay = 15000

    //adding my RadToolTip in my controller
    protected override void CreateChildControls()


References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>