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

  • Home
  • SEARCH
  • 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 8333537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:04:08+00:00 2026-06-09T03:04:08+00:00

I am writing a service layer which uses Entity framework to get/set data from

  • 0

I am writing a service layer which uses Entity framework to get/set data from the database, and then pass it to an MVC web application. I am not able to decide what is the bext way to return database errors to the web application.

Should I throw an exception and the web application can handle it accordingly, or should I return a string/bool to convey that the database action has worked or not?

Any suggestion on what is the best practice?

Thanks

  • 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-06-09T03:04:09+00:00Added an answer on June 9, 2026 at 3:04 am

    You can either not handle them in your service layer, or you can normalize them using an exception class that you will create. For example:

    public class DatabaseException: Exception
    {
        public string TableName { get; private set; }
    
        public DatabaseException(string tableName, Exception innerException)
            :base("There a database error occured.", innerException)
        {
            TableName = tableName;
        }
    }
    

    Simply add whatever information you require to the exception class as properties and initialize them in the constructor.

    It’s really not the best practice to inform the higher levels about exceptions with return values, since most of the methods are already returning some data.

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

Sidebar

Related Questions

I am writing a service layer application, which interacts with database using Entity framework.
I am writing WCF service that uses wsHttpBinding binding, which is not hosted in
I'm writing a simple movie database which has a three tier stack of service
In my ASP.NET MVC project, my actions typically call a Service layer to get
ProductA uses our only web service, which is a separate deployment from ProductA. We
I'm data-binding a ListView to a collection that comes from a service layer. In
I'm writing a Windows Service that needs to take a file from an FTP
I am writing unit tests for service layer in my spring application. Here is
I have a Silverlight 4 app which pulls entities down from a database using
I have a framework which works this way: After defining some meta data, it

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.