Bug SS-2313
1 vote

[DEV] MathException

Created by Davide on 4/11/2016 7:42 PM Last Updated by Davide on 4/12/2016 8:01 PM
%
 (hrs)
Logged: 0   (hrs)

 Description

throw new MathException(Errors.CanNotFindFile, new Term(Symbols.StringChar + "whatever" + Symbols.StringChar, TermType.Operand, 0));

From the exception above I expect to see in the canvas: "Cannot find the file: whatever", but all that I get is "Cannot find the file: "; I'm doing something wrong?

    Davide (Tuesday, April 12, 2016 8:01 PM) #

Thank you Andrey, it works!

Once there is an easy way, is not a priority from my side; because there are several exceptions with arguments (f.e. AlertsOccuredOnFileOpen), I suggest to think if it may be better to extend MathException for each one and/or to have something general (using params[] ?);

Also, I noticed there isn't a MathException(Errors,Entry)

    smath (Tuesday, April 12, 2016 2:35 PM) #

Initially this error message was introduced to be used in the following scenario:

  MessageBox.Show(GeneralException.GetErrorText(Errors.CanNotFindFile) + context.FileName, GlobalParams.Info.Title);

So, there is no easy way to do what you need.

My suggestion is to create your own Exception class like this (did not test it):

    public class ExternalFileNotFoundException : MathException
    {
        public override string Message
        {
            get
            {
                return GeneralException.GetErrorText(Errors.CanNotFindFile) + base.Element.Text.Replace(Symbols.StringChar, String.Empty);
            }
        }
 
        public ExternalFileNotFoundException(Term Variable)
            : base(Errors.CanNotFindFile, Variable)
        {
        }
    }
 
May be I need to include this class directly into SMath Studio. What do you think?