Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it legal to throw the same exception for different reasons?
    text
    copied!<p>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.</p> <pre><code> //.. //... // &lt;exception cref = "ErrorInScriptException"&gt;Wrong number of tokens.&lt;/exception&gt; // &lt;exception cref = "ErrorInScriptException"&gt;Variable not found.&lt;/exception&gt; // &lt;exception cref = "ErrorInScriptException"&gt;Variable type is not string.&lt;/exception&gt; // &lt;param name = "splitScriptLine"&gt;Split script line to be interpreted.&lt;/param&gt; private void MakeString(IList&lt;string&gt; splitScriptLine) { //check minimum of 3 tokens if (Tokens &lt; 3) { throw CreateErrorInScriptException("IDS_Invalid_Token"); } var dummy = string.Empty; //read strings for (var z = 2; z &lt; 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; } } </code></pre> <p>Note: as shown in code above, I'm throwing the ErrorInScriptException in three cases, I change only the message. <br/></p> <pre><code>[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 } /// &lt;summary&gt; /// Creates a script error. /// &lt;/summary&gt; /// &lt;param name = "message"&gt;Message to be shown.&lt;/param&gt; /// &lt;returns&gt;ErrorInScriptException or the script error.&lt;/returns&gt; 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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload