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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:29:11+00:00 2026-05-17T20:29:11+00:00

I have class that predominately consists of gather string input and then subsequently outputting

  • 0

I have class that predominately consists of gather string input and then subsequently outputting the data in a certain format. The result of the class is basically a ToString() override.

With my class I have a static method string Print(string path) that reads the inputs from a flat file. It then parses these inputs and generates an instance of a class for each record in the flat file. Then for each instance of the class I call the class.ToString() and append it to the stringbuilder that eventually gets returned within Print().

I ensure that each record has the necessary values and have appropriate range, if they do not I need to throw an exception. I’ve never done exception handling before so I want to know if what I want to do is even possible.

When an exception case gets thrown, I want to take whatever is in the stringbuilder add the closing tag cleanup stuff and then prepend the exception text to the stringbuilder and then return (Exception Error Text + stringbuilder.ToString() + FooterStuff).

Edit Code:

It might not actually be a good idea to throw an exception, I might just need to use a try{} catch {} to catch an exception and then append the exception.message to the beginning of the stringbuilder. I don’t really know though, exceptions are fairly new to me.

public class Record
{
    public string Name;
    public string Value;
    ...

    private Dictionary<string, LogFormat> = new LogFormat.Table();

    public static string Print()
    {
          Stringbuilder sb = new StringBuilder();
          var k = ReadLog();

          foreach (var x in k)
          {
               sb.Append(x.ToString());
          }

          return sb.ToString();
    }

    public override string ToString()
    {
        if (Table[Name].NeedsValue && (Value == String.Empty || Value == null))
        {
            throw new Exception();
        }

        return String.Format(Table[Name].Format, Attribute, Value);
    }
}

public class LogFormat
{
     public string Format;
     public bool NeedsValue = false;

     public Dictionary<string,LogFormat> Table()
     {
           Dictionary<string,LogFormat> dct = new Dictionary<string,LogFormat>();
           dct.Add("Address", new LogFormat(){Format = "Street:{0}\nCity:{1}"});
           ...
           return dct;
     }
}
  • 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-17T20:29:12+00:00Added an answer on May 17, 2026 at 8:29 pm

    You can try something like that:

    private string YourMethod()
    {
        var sb = new StringBuilder();
    
        try
        {
            // Do your stuff
        }
        catch (ASpecificException ex)
        {
            sb.Insert(0, ex.Message);
        }
        finally
        {
            sb.Append("YourFooter");
        }
    
        return sb.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I instantiate to save or load xml data. For
I have a class that gets a movieClip and then using addChild adds it
I have class BaseClass that contains a few methods like public Result mothodA(Token token,
I have class that extends 'IntentService' - this class occasionally receives data from a
I have class that has a property that is of type string[]. I need
I have class that retrieves a date from a certain file. After I make
I have class A that derives from System.Data.Objects.DataClasses.EntityObject . When I try to serialize
I have class that extend FragmentActivity in it I add fragment to layout as
I have class that looks like this: class A { public: class variables_map vm
I have class that represents users. Users are divided into two groups with different

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.