[CLOSED] How to properly handle exceptions in Direct Events?

  1. #1

    [CLOSED] How to properly handle exceptions in Direct Events?

    Hi,

    Please provide the best practice and preferrably a code sample to handle exceptions thrown in DirectEvent code.

    Thanks,

    Vadym
    Last edited by Daniil; Feb 10, 2012 at 3:22 PM. Reason: [CLOSED]
  2. #2
    Hi,

    DirectEvent/DirectMethod has Failure handler.

    A DirectEventArgs instance has the Success and ErrorMessage properties.

    Here is the example how to handle exceptions in DirectMethods.
    http://examples1.ext.net/#/Events/Di...ds/Exceptions/

    There is the AjaxRequestException handler in ResourceManager to handle exceptions globally. Here is some example:
    http://forums.ext.net/showthread.php?9261

    Store has the Exception event.

    Hope this helps.
  3. #3
    Thanks Daniil,

    Do you have any actual code example dealing with Direct Event exception handling? After throwing an exception, the flow of execution simply continues in the Event code. I want it to stop, go to the error handler and present an error message popup on the client side.

    Thanks,

    Vadym
  4. #4
    There won't be any changes compared to the example with DirectMethods:
    http://examples1.ext.net/#/Events/Di...ds/Exceptions/
    apart from using
    A DirectEventArgs instance has the Success and ErrorMessage properties.
    instead of
    Ext.Net.ResourceManager.AjaxSuccess = false;
    Ext.Net.ResourceManager.AjaxErrorMessage = e.Message;
    and using the DirectEvent's Failure handler instead of the DirectMethod's "failure" one.
  5. #5
    Here's my code:

                            <ext:Button ID="ButtonSave" runat="server" Text="Save" Icon="Disk" Width="80">
                                <DirectEvents>
                                    <Click Before="if (!#{Form1}.getForm().isValid()) {
                                                            Ext.net.Notification.show({
                                                            iconCls: 'icon-exclamation',
                                                            html: 'Form is invalid!',
                                                            title: 'Error'
                                                        });
                                                        return false;
                                                    }" OnEvent="ButtonSave_Click" Failure="Ext.Msg.alert(failure);"
                                        Success="
                                                        var form=#{Form1};
                                                        if (form.record == null) {
                                                            return false;
                                                        }
    
                                                        form.getForm().updateRecord(form.record);">
                                        <EventMask ShowMask="true" />
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
    On Failure, I'd like to present a popup with an error message. I need to get the value of the failure parameter in the Failure handler. Please help me with the correct syntax.

    Thanks,

    Vadym
  6. #6
    result.errorMessage
    Here is the full example.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void TestDirectEventHandler(object sender, DirectEventArgs e)
        {
            e.Success = false;
            e.ErrorMessage = "I'm the Error!";
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Button runat="server" Text="Click me">
                <DirectEvents>
                    <Click OnEvent="TestDirectEventHandler" Failure="alert(result.errorMessage);" />
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
    Btw, there is a simple way to quickly investigate arguments of any handler.
    <DirectEvents>
        <Click OnEvent="TestDirectEventHandler" Failure="debugger;" />
    </DirectEvents>
  7. #7
    That's exactly what I was after! Very much appreciated. This debugger quirk may come pretty handy, too.

    I believe, global exception handling is done differently as I've seen traces of this discussion on the forum.

    Thanks,

    Vadym
  8. #8
    Quote Originally Posted by vadym.f View Post
    I believe, global exception handling is done differently as I've seen traces of this discussion on the forum.
    Well, the main difference is the fact that a failure case is handled within the ResourceManager's AjaxRequestException listener.

Similar Threads

  1. Direct Events with Razor
    By gdog_5021 in forum 2.x Help
    Replies: 3
    Last Post: Aug 15, 2012, 10:46 AM
  2. [CLOSED] How to Call an event by Direct Events
    By Oliver in forum 2.x Premium Help
    Replies: 2
    Last Post: Jun 12, 2012, 6:33 PM
  3. Direct Events dynamic Url
    By Tallmaris in forum 1.x Help
    Replies: 1
    Last Post: Aug 18, 2011, 1:26 PM
  4. How to handle events
    By costab in forum 1.x Help
    Replies: 2
    Last Post: Apr 26, 2011, 11:09 PM
  5. [CLOSED] Direct events in user control
    By tiramisu in forum 1.x Premium Help
    Replies: 8
    Last Post: Dec 13, 2010, 11:34 AM

Tags for this Thread

Posting Permissions