comexception.cs

来自「c--解释器」· CS 代码 · 共 96 行

CS
96
字号
using System;
using System.Collections.Generic;
using System.Text;

namespace compiler
{
    class ComException : Exception
    {
        //所在行
        int row;

        //所在列
        int col;

        //异常类型
        int expType;

        //信息
        string displayWord;
        
        //constructor

        public ComException(int rowfrom, int colfrom, int expTypefrom)
        {
            this.row = rowfrom;
            this.col = colfrom;
            this.expType = expTypefrom;
            this.displayWord = "There is a mistake at row " + this.row + "column" + this.col
                               + "the Error type is " + this.getTypeString();



        }

        public ComException(int rowfrom, int expTypefrom)
        {
            this.row = rowfrom;
            
            this.expType = expTypefrom;
            this.displayWord = "There is a mistake at row " + this.row +"  "
                               + "the Error type is " + this.getTypeString();



        }

      /*  void display() 
        {
            string displayWord = "There is a mistake at row " + this.row + "column" + this.col;
            
        
        }
        */


        //返回信息
        public string getMessage() 
        {
            return this.displayWord;
        
        }

        //返回错误类型
        public string getTypeString() 
        { 
          switch(this.expType)
          {
              case 0: return "confused error";

              case 1: return "常量定义错误";
                  
              case 2: return "漏掉分号";
                 
              case 3: return "漏掉‘]’";
                  
              case 4: return "数组定义错误";
              
              case 5: return "变量定义错误";

              case 6: return "方法头错误";
              
              case 7: return "方法体错误";
              case 8: return "表达式错误";
              case 9: return "漏掉 } ";
              case 10: return "数字类型错误";
                  
              default: return "wrong";
                 
          
          }
        
        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?