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 524585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:35:00+00:00 2026-05-13T08:35:00+00:00

I created a custom exception public class InvalidUsernameException : ApplicationException { public InvalidUsernameException() {

  • 0

I created a custom exception

public class InvalidUsernameException : ApplicationException
{
    public InvalidUsernameException()
    {
    }
}

After that I throw this exception in a method

public static DataTable GetTableForApproval()
{
    using (var connection = Utils.Database.GetConnection())
    using (var command = new SqlCommand("SELECT [UserID], [Username], [Email], [Role], [Date] FROM [Users] WHERE [Role] = @role", connection))
    {
        command.Parameters.AddWithValue("@role", "Waiting");
        using (var reader = command.ExecuteReader())
        {
            if (reader == null || !reader.HasRows)
                throw new NoFormsForAuthenticaionException();

            var table = new DataTable();

            table.Columns.Add("UserID", typeof(int));
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Email", typeof(string));
            table.Columns.Add("Role", typeof(string));
            table.Columns.Add("Registration date", typeof(DateTime));

            while (reader.Read())
                table.Rows.Add((int)reader["UserID"], (string)reader["Username"], (string)reader["Email"], (string)reader["Role"], (DateTime)reader["Date"]);

            return table;
        }
    }
}

And when I use these method I catch the exception

try
{
    GvApproveUser.DataSource = Authentication.GetTableForApproval();
    GvApproveUser.DataBind(); 
}
catch (NoFormsForAuthenticaionException)
{
    Error.HandleError("There is no forms for approval");
}

This is the code behind the Error page

public partial class Error
{
    public static string GetUrl(string message)
    {
        return string.Format("~/Error.aspx?errorMessage={0}", message);
    }

    public static void HandleError(string message)
    {
        HttpContext.Current.Response.Redirect(GetUrl(message), false);
    }

    protected override void OnPreRender(System.EventArgs e)
    {
        base.OnPreRender(e);

        LblError.Text = ErrorMsg;
    }

    private string ErrorMsg
    {
        get
        { 
            return  Request["errorMessage"] ?? string.Empty;
        }
    }
}

Is there a easier way to post this error message? Can I do this without violating the rules of 3-tier architecture? Is there another way?

public class InvalidUsernameException : ApplicationException
{
    public InvalidUsernameException()
    {
        Error.HandleError("There is no forms for approval");
    }
}
  • 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-13T08:35:00+00:00Added an answer on May 13, 2026 at 8:35 am

    The first thing to note is that you are using an exception for something that does not appear to be an exceptional circumstance; having no rows seems like both a reasonable and expected state of affairs. So, if it isn’t an exceptional case, don’t use an exception.

    I’d probably change the data access method to not throw, and then simply check whether there are any rows in the table, which means your code would simplify down to something like this:

    var table = Authentication.GetTableForApproval();
    if (table.Rows.Count == 0)
    {
        Error.HandleError("There are no forms for approval");
    }
    
    GvApproveUser.DataSource = table;
    GvApproveUser.DataBind();
    

    The next potential simplification is to decide whether you really want to redirect to an error page for something like this. Why not just show a message instead of the gridview that indicates there is nothing to approve? Then you keep it all on one page and everything becomes very simple as there is just one page with no custom exceptions and no special error page, e.g.

    var table = Authentication.GetTableForApproval();
    if (table.Rows.Count > 0)
    {
        GvApproveUser.DataSource = table;
        GvApproveUser.DataBind();
    }
    else
    {
        // hide the gridview and show a message
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Regarding imputation of categorical data, I would suggest to check… May 14, 2026 at 10:09 pm
  • Editorial Team
    Editorial Team added an answer Add to vimrc: :let manpageview_multimanpage=0 pgup-pgdn mapped to changing sections… May 14, 2026 at 10:09 pm
  • Editorial Team
    Editorial Team added an answer This works for me: NSURL *myURL = [[NSURL alloc] initWithString:@"http://www.google.com"];… May 14, 2026 at 10:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.