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

The Archive Base Latest Questions

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

This a code is 10 years old, without error handling. The code comes from

  • 0

This a code is 10 years old, without error handling. The code comes from a simple script interpreter without parser or scanner, I’m trying catch all errors in the interpreter and return a suitable error with error message.

    //..
    //...
    // <exception cref = "ErrorInScriptException">Wrong number of tokens.</exception>
    // <exception cref = "ErrorInScriptException">Variable not found.</exception>
    // <exception cref = "ErrorInScriptException">Variable type is not string.</exception>
    // <param name = "splitScriptLine">Split script line to be interpreted.</param>
    private void MakeString(IList<string> splitScriptLine)
    {
        //check minimum of 3 tokens
        if (Tokens < 3)
        {
            throw CreateErrorInScriptException("IDS_Invalid_Token");
        }

        var dummy = string.Empty;

        //read strings
        for (var z = 2; z < Tokens; z++)
        {
            dummy = dummy + ReadStringToken(splitScriptLine[z]);
        }

        var variable = VariableList[splitScriptLine[1], FileIncludeLevel];

        //no string var detected
        if (variable == null)
        {
            throw CreateErrorInScriptException("IDS_116");
        }

        //write new string to destination var
        if (variable.Identifier.Equals(splitScriptLine[1]))
        {
            //variable found
            if (variable.VariableType !=
                VariableType.String)
            {
                throw CreateErrorInScriptException("IDS_113");
            }

            variable.Value = dummy;
            variable.IsVarString = true;
        }
    }

Note: as shown in code above, I’m throwing the ErrorInScriptException in three cases, I change only the message.

[Serializable]
public class ErrorInScriptException : UniLoadApplicationException
{
    #region Constructors

    public ErrorInScriptException(string error)
        : base(error)
    {
    }

    #endregion Constructors


    #region Properties

    public string ErrorCode { get; set; }

    public string FileName { get; set; }

    public int LineNumber { get; set; }

    public string ScriptLine { get; set; }

    #endregion Properties
}



/// <summary>
///   Creates a script error.
/// </summary>
/// <param name = "message">Message to be shown.</param>
/// <returns>ErrorInScriptException or the script error.</returns>
protected Exception CreateErrorInScriptException(string message)
{
    var ex = new ErrorInScriptException(message)
             {
                ScriptLine = CurrentScriptLine,
                LineNumber = CurrentLineNumber,
                FileName = CurrentFileName,
                ErrorCode = message
             };
        ex.Data["Info"] = new ExceptionInfo(ErrorLevel.Error, message)
                      {
                        ExitApplication = false
                      };
        return ex;
}
  • 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-27T08:47:56+00:00Added an answer on May 27, 2026 at 8:47 am

    This is usually ok. However, if you intend those exceptions to be caught and dealt with by code (instead of just signalling an error that the user has to deal with), you might want to create appropriate subclasses that detail the kind of error.

    I.e.

    class InvalidTokenException : ErrorInScriptException {}
    class NoStringVarException : ErrorInScriptException {}
    ...
    

    But unless those exceptions are intended for code to react to different errors differently I don’t think this makes much sense. To a user the exception message is relevant and that could be achieved with any Exception class.

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

Sidebar

Related Questions

This is code that worked fine on Windows XP for years. User is not
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
If I come across old code that does if (!this) return; in an app,
So, I was going over some old code I wrote about 5 years ago
As I was learning from couple of years old tutorials I have end up
I have some ancient code (5 years old) and how I used to access
I have been asked to update some old code I worked on years ago.
When I write this code, I get an error on the Sort() Method. ArrayList
First a little intro: Last year i wrote this http://dragan.yourtree.org/code/canvas-3d-graph/ Now, i want to

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.