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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:47:41+00:00 2026-05-27T13:47:41+00:00

I have the following code: public IDictionary<string, string> GetNextBase36(string partitionKey, string rowKey, ref string

  • 0

I have the following code:

    public IDictionary<string, string> GetNextBase36(string partitionKey, string rowKey, ref string seq)
    {
        Sequence sequence;
        try {
            sequence = _sequenceRepository.Get(u => u.PartitionKey == partitionKey & u.RowKey == rowKey);
        } catch {
            _errors.Add("", "Database error: Get sequence failed");
        }
        try {
            sequence.Value = Base36.Encode(Base36.Decode(sequence.Value) + 1);
            _sequenceRepository.AddOrUpdate(sequence);
            seq = sequence.Value;
        } catch {
            _errors.Add("", "Database error: Updating sequence failed");
        }
        return _errors;
    }

It works but it seems overkill to have each database access surrounded by a try catch block. Is there some way I could simplify this? Is there any beter approach?

Updated code based on help / advice:

    public IDictionary<string, string> GetNextBase36(string partitionKey, string rowKey, ref string seq)
    {
        Sequence sequence;
        string catchMsg = string.Empty;
        try {
            catchMsg = "Database error: Get sequence failed"
            sequence = _sequenceRepository.Get(u => u.PartitionKey == partitionKey & u.RowKey == rowKey);
            sequence.Value = Base36.Encode(Base36.Decode(sequence.Value) + 1);
            catchMsg = "Database error: Updating sequence failed"
            _sequenceRepository.AddOrUpdate(sequence);
            seq = sequence.Value;
        } catch {
            _errors.Add("", catchMsg);
        }
        return _errors;
    }
  • 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-27T13:47:41+00:00Added an answer on May 27, 2026 at 1:47 pm

    You are sacrificing exact exception stack traces on the altar of error message readability (not to mention code readability).

    Consider your audience: a developer. A developer should be able to read an exception stack trace, which is much more valuable debugging information than a short error message.

    Hence my suggestion is to only put in one exception handler for logging somewhere higher up the hierarchy. If you have to have one in your current method, at least capture the full exception stack trace.

    Also – does it really make sense to continue after the first exception? If retrieving the sequence fails, using its value in the next try block won’t fair any better. It does not make sense having multiple try/catch blocks here, unless you know exactly how to solve the problem in each catch handler so you can continue.

    Update:

    Now that you have a single try/catch block code readability is improved. It still looks very odd that you are basically returning a list of errors to the caller – the error case should be exceptional, so it should not bleed into the business logic of your method, instead I would just let the exception go up the stack until you can truly handle the problem (or just log it and exit the app).

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

Sidebar

Related Questions

I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: public IDictionary<string, int> GetCountByDate(DateTime fromDate, DateTime toDate) { var
I have the following code: public class Alert { public string Alias { get;
I have the following code: public static T ParameterFetchValue<T>(string parameterKey) { Parameter result =
i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
I have the following code: public class AppDomainArgs : MarshalByRefObject { public string myString;
I have the following code: public static class ScraperMasterUriDetails { public static Dictionary<Guid, string>
I have the following custom property in my code: public Dictionary<int, string> ServiceIdList {
I am using EF 4 and have the following code. public static Dictionary<Tuple<int, string>,
I have following code snippet into c# public class Client { public string ID

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.