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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:07:53+00:00 2026-05-12T23:07:53+00:00

This issue is technology agnostic, but I am working with C# and ASP.NET and

  • 0

This issue is technology agnostic, but I am working with C# and ASP.NET and will use this for the pseudo code. Which is the better approach, and why?

  1. Encapsulate logging, transaction and exception handling:

    protected void Page_Load(object sender, EventArgs e) {
     SomeBusinessClass.SomeBusinessMethod();
    }
    
    
    public class SomeBusinessClass {
      public void SomeBusinessMethod() {
        using (TransactionScope ts = new TransactionScope()) {
                    doStuff();
                    ts.Complete();
                }
                catch (Exception ex) {
                    LogError("An error occured while saving the order", ex);
                }
            }
        }
    }
    
  2. Delegate logging, transaction and exception handling to the caller:

    protected void Page_Load(object sender, EventArgs e) {
        using (TransactionScope ts = new TransactionScope()) {
              try {
                    SomeBusinessClass.SomeBusinessMethod();
                    ts.Complete();
              }
              catch (Exception ex) {
                    LogError("An error occured while saving the order", ex);
              }
         }
    }
    
    
    public class SomeBusinessClass {
      public void SomeBusinessMethod() {
          doStuff();
        }
    }
    

I am concerned that by introducing dependencies on logging, transactions, etc in my business logic code, I make it less generic. On the other hand, the UI code looks so much cleaner. I can’t make the call. Let me know what other factors I should consider.

  • 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-12T23:07:53+00:00Added an answer on May 12, 2026 at 11:07 pm

    Transactions: a central concern of your business layer, so it should absolutely handle this (though you might centralize transaction handling via a unit of work implementation).

    Update: I don’t agree with this part any more. Often, the controller, presenter, or or another top-level caller is the best place to handle transactions (a la the the onion architecture) – in many cases, that’s where the logical unit of work is defined.

    Exception Handling: use as needed in every layer – but only use it in the business layer when you can actually do something about it (not just log it). Use a global handler in the UI layer if your infrastructure supports one.

    Logging: use trace or informational logging in whatever layers need it, only log exceptions in the top layer.

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

Sidebar

Related Questions

This issue is somewhat related: Problem with Code Generated by XSD.EXE: Sequence of Elements
Has anyone else had this issue and found a working solution? I've enabled the
I know this issue has been touched on here but I have not found
I understand this is an old technology, but I have been using it forever
Technology used: .NET 2008, C#, winforms So I currently have an issue. I have
Well the problem is that I am new to asp.net technology and I am
This issue has me baffled, it's affecting a single user (to my knowledge) and
Note: This issue appears to be limited to SQL Server 2005 SP2 I have
EDIT: This issue is already submitted on Github. Changing the Act part to this
Update: This issue was not properly explored. The real issue lies within render :json

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.