Returning Exceptions

Rate It (1)

Last post 03-15-2006 4:52 AM by Luis Abreu. 8 replies.

Sort Posts:

  • Returning Exceptions

    02-17-2006, 4:55 PM
    • Member
      145 point Member
    • craigpearson
    • Member since 03-04-2004, 1:14 PM
    • Posts 29
    Hi

    Using the example:
    http://atlas.asp.net/quickstart/atlas/doc/services/default.aspx#catchingExceptions

    Both IE and FF throw javascript errors

    FF: result has no properties
    IE: 'null' is null or not an object  - 'null' being the result argument from the OnError callback method

    See for youself:
    http://atlas.asp.net/quickstart/atlas/samples/services/ExceptionPage.aspx

    Is this a bug with the Jan06 release?  What is the best way around this?

    Craig
  • Re: Returning Exceptions

    02-20-2006, 12:09 AM
    • Member
      15 point Member
    • iFusion
    • Member since 02-20-2006, 5:08 AM
    • Posts 3

    I just downloaded the Jan06 release and I'm experiencing the same problem...

  • Re: Returning Exceptions

    02-21-2006, 4:30 AM
    • Member
      160 point Member
    • hecchan
    • Member since 01-12-2005, 3:16 AM
    • lugo
    • Posts 32

    Hi people,

    i'm using January release also, when i run the example from the Atlas quickstart site, i got the same exceptions.

    But if i try the example locally (copy the examples to my computer Atlas site), they are working well.

    I think the Atlas site is using an older release.

    So, Atlas team please, update the quickstart samples site. It's very important for the people who are starting with Atlas have confidence about the samples

    This way it's much harder to find the errors.

     

    thanks for listening,
    hecchan
  • Re: Returning Exceptions

    02-21-2006, 11:48 AM
    • Member
      145 point Member
    • craigpearson
    • Member since 03-04-2004, 1:14 PM
    • Posts 29

    Actually, I can reproduce the problem running the example locally.  In my scenerio, I use an ASPX page to host the web method as follows:

    MyPage.aspx.cs
    [WebMethod]
    public void GetData() {
      throw new ArgumentException("throw exception");
    }

    MyPage.aspx
    <script language="javascript" type="text/javascript">
      function CallServer() {
       
    PageMethods.GetData(,OnComplete, OnTimeout, OnError);
      }

      function OnComplete() {
       alert("Complete");
      }

      function OnTimeout(result) {
       alert(result);
      }

      function OnError(result) {
       alert(result);
      }
    </script>

    <!-- Call the server from a HTML button  -->
    <input type="button" value="Call Server" onclick="CallServer();"/>

  • Re: Returning Exceptions

    02-21-2006, 12:54 PM
    • Member
      160 point Member
    • hecchan
    • Member since 01-12-2005, 3:16 AM
    • lugo
    • Posts 32

    you're right,

    If i move the method to the same page, i got a null argument in the error delegate.

    I tried to add

    <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true"

    OnPageError="OnScriptManagerPageError">

    <ErrorTemplate>

    Ha ocurrido un error al procesar esta acción.<br />

    <span id="errorMessageLabel"></span>

    <hr />

    <button id="okButton" type="button">

    OK</button>

    </ErrorTemplate>

    </atlas:ScriptManager>

    and the server script

    <script type="text/C#" runat="server">

    [WebMethod]

    public void ExceptionTest(String someParam)

    {

    throw new InvalidOperationException("foo");

    }

    protected void OnScriptManagerPageError(object sender, PageErrorEventArgs e)

    {

    // Set e.ErrorMessage to something you want to send down to the client

    e.ErrorMessage = (String.IsNullOrEmpty(e.Error.InnerException.Message)) ? e.Error.Message : e.Error.InnerException.Message;

    }

    </script>

    as i have seen at

    http://www.nikhilk.net/AtlasM1Refresh.aspx

    and the server function OnScriptManagerError is not called, even i checked with fiddler that the server response code is 500.

    I'd like to know how to use the new feature of page error handling

    thanks for listening,
    hecchan
  • Re: Returning Exceptions

    03-14-2006, 9:49 AM
    • Member
      19 point Member
    • rickduarte
    • Member since 03-13-2006, 1:57 PM
    • Posts 6

    Same problem here.
    I'm executing a WebMethod and the error handling are returning a null value.

    Somone knows how to catch error returned from the WebMethod?

    It's a bug in Jan06?

  • Re: Returning Exceptions

    03-14-2006, 2:50 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 1:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello guys.

    well, i may be wrong since i've only started lookig at atlas today and i've also got this bug while throwing exceptions from web methods defined on the page. after trying to do some debugging, it looks like the problem is on Web.Net.WebResponse.get_objectmethod. the problem is that it gets the result and tries to deserialize it. however, when a method on a page throws an error, the result that is received on the client part is an html page which de JSON can't deserialize. this seems like a bug on the scriptmanager (is this the component that handles server side processing when one calls methods on a page? - ehy, don't forget that i just started today on this :) )
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Returning Exceptions

    03-15-2006, 4:42 AM
    • Contributor
      7,416 point Contributor
    • Garbin
    • Member since 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,506
    • ASPInsiders
      TrustedFriends-MVPs
    Hi,

    we can distinguish 3 cases:

    1) The Exception is raised in a method defined in a WebService.
    In this case, an instance of the class Web.Net.MethodRequestError is sent to the client. This object exposes three properties that give info on the particular Exception raised: get_message(), get_stackTrace(), get_exceptionType().

    2) The Exception is raised during an asynchronous postback.
    This means we have declared at least one UpdatePanel. The Exception can be raised, for example, in an event handler during the Page lifecycle.
    In this case, the ScriptManager is able to send the error message down to the client and to display it using its <ErrorTemplate />. Moreover, the server can format the message to be sent to the client by handling the PageError event of the ScriptManager.

    3) The Exception is raised when calling a [WebMethod] defined in a Page.
    In this case, no exception handling is performed by the Atlas framework, and the client receives (in the response) the tipical HTML page that is displayed on ASP.NET pages when an Exception is raised.

    At this point, the the error callback could be declared in this way:

    function onError(objError, response) {
        if(objError) {
           // Got a MethodRequestError instance.
        }
        else {
            // Custom error handling.
            alert(response.get_statusCode());
        }
    }


    While the objError parameter is null, the second parameter is the response object and we can use it to display, for example, an alert with the HTTP status code (obviously, while waiting for an improved exception handling in the next release).
    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: Returning Exceptions

    03-15-2006, 4:52 AM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 1:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello.

    yes, i got into that conclusion after debugging the atlas script file...i think that it should be fixed before the final release...
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
Page 1 of 1 (9 items)