Transferring to a custom error page from a class

Last post 08-17-2005 6:29 AM by meetviral. 3 replies.

Sort Posts:

  • Transferring to a custom error page from a class

    08-17-2005, 5:22 AM
    • Participant
      1,585 point Participant
    • smtraber
    • Member since 05-30-2005, 6:34 AM
    • California, US
    • Posts 344
    I'm using a try catch block for all the functions in my data access layer, and if there is an error, i want to redirect the user to my custom error page, but my data access layer consists of classes and not forms, and the classes don't recognize the response.redirect, or server.transfer methods. How can I transfer them to the error page from these classes?

    Thanks in advance,

    smtraber
    Victory is mine!!
  • Re: Transferring to a custom error page from a class

    08-17-2005, 5:34 AM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027
    You should not do this. The Data Access layer should be agnostic to whether you are creating a Windows Forms, ASP.NET, or console application. You should throw the exception higher, at least up into your busines layer.

    If you insist, however, you get get a handle on the current Response object like this:

        System.Web.HttpContext.Current.Response.Redirect( "~/error.aspx", true )
     
    Be sure to include the second argument (true) if you are using this command inside a Catch block.
    Alister
  • Re: Transferring to a custom error page from a class

    08-17-2005, 5:39 AM
    • Member
      142 point Member
    • yvespeneveyre
    • Member since 05-07-2003, 10:58 AM
    • Chavornay, Switzerland (near Lausanne)
    • Posts 27

    Hello !

    From your data access layer, you should return an error code, or, better, throw an (specialized - inherited) exception to the calling layer. This lets you the choice of the proper reaction to your presentation layer or your controller.
    Furthermore, for unhandled exceptions, there is a way to catch them in a single event handle located in the global.asax file (see the .NET documentation for more details).

    Hope it helps

    Regards


    ------------------


    Yves Peneveyre





    E-mail : yves dot peneveyre at ctp dot com
  • Re: Transferring to a custom error page from a class

    08-17-2005, 6:29 AM
    • Member
      5 point Member
    • meetviral
    • Member since 08-17-2005, 4:43 AM
    • Ahmedabad
    • Posts 1
    You can do one thing. Remove try catch from your data access layer and apply it to the calling level of that data access layer.
    For example you can write below in WEB application

    MyDataClass objData=new MyDataClass();
    try
    {
    objData.execute();
    }catch(Exeption e)
    {
    }

    Viral
Page 1 of 1 (4 items)