Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:14:22+00:00 2026-05-29T21:14:22+00:00

1)I have the PageBase class that inherits from Page Class. The all code behind

  • 0

1)I have the PageBase class that inherits from Page Class. The all code behind inherit from PageBase class. So I want to add the exception handling logic to PageBase class.

In Page_Error Event I added the logic to handle the exception, but the I want page to be rendered properly with exception details showing on the top of Web Page.

e.g

On web form I have button control that updates the data in Database. On button click i have the logic to update the data. While updating it may throw exception. I dont want to put Try catch block on button click save logic. Instead I want some method or event on PageBase to catch the exception and render the page entirely with all controls and exception in the header.

2)`// in the Base class of CodeBehind page, I have Written

protected void TryAction(Action action)
{
  try
  {
    action();
  }
  catch(Exception e)
  {
    // write exception to output (Response.Write(str))
  }
}

In CodeBehind I have written the code for Button Click Event

Private List<T> GetData(string a, string b)
{
  List<T> _lst;
  TryAction(()=>{
     //Call BLL Method to retrieve the list of BO.
     _lst = BLLInstance.GetAllList(a,b);
  });
  return _lst;
}

This Works fine, I want,

Private List<T> GetData(string a, string b)
{
  TryAction(()=>{
     //Call BLL Method to retrieve the list of BO.
     return BLLInstance.GetAllList(a,b);
  });
}

It is Showing the Error”System.Action retuens void”, Can you please tell me how to use TryAction Method if we have return type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:14:24+00:00Added an answer on May 29, 2026 at 9:14 pm

    When the exception is thrown, if you don’t catch it, it will bubble up to Page_Error and then Application_Error. Once it gets to Page_Error tho it’s already broken the page rendering. I don’t think there’s a way to continue rendering the rest of the page. If you’re looking to increase code re-use of your error handling logic you could use an anonymous method.

    // on your base page
    protected void TryAction(Action action)
    {
        try
        {
            action();
        }
        catch(Exception e)
        {
            // write exception to output (Response.Write(str))
        }
    }
    
    protected void TryFunction<T>(Function<T> func)
    {
        try
        {
            return func();
        }
        catch(Exception e)
        {
            // write exception to output (Response.Write(str))
    
            return default(T);// have to return something now because it's a function.
        }
    }
    

    then your data access method could look like

    protected void Button1_Click(object sender, EventArgs e)
    {
        TryAction(() => {
            // Do stuff here - save to database etc
        });
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        return TryFunction<string>(() => {
            // Do stuff here - save to database etc
            return "woo";
        });
    }
    

    It is worth noting that if an exception occurs in the function you might not get a useful value back from it and you should code accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named PageBase inheriting from ASP.NET Page . I want to
I have a custom PageBase class that I am using for all of the
I have a security class that is called by a PageBase class (that all
I have a page base class that has no .aspx file and so I
Have a photography site that I want to prevent image copying from. How can
Have a script to add / remove options from a select field -- the
I have a page base class (.NET4): public class SitePageBase : System.Web.UI.Page { protected
have next code: class GameTexture { private: LPDIRECT3DTEXTURE9 texture; unsigned char *alphaLayer; UINT width,
I have a PageBase page in App_Code. In it is a function called LoadContext().
here's the code (simplified): public abstract class PageBase implements Serializable { private static final

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.