日期:2014-05-18  浏览次数:20812 次

定义一个抛出异常的类,有语法错误
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication21
{
  class MyException throws IndexOutOfRangeException
  {
  public int[] myArray=new int[4]{1,2,3,4};
  }
  class TestException
  {
  static void Main()
  {
  MyException me=new MyException();
  try
  {
  me.myArray[5]=5;
  }
  catch(IndexOutOfRangeException ex)
  {
  Console.WriteLine("出现错误了!");
  Console.WriteLine(ex.Data.ToString());
  }
  Console.WriteLine();
  }
  }
}
书上的代码,红色的字给出了红色的波浪线,哪里出问题了?

------解决方案--------------------
throws IndexOutOfRangeException ,C# 没有这语法吧,去掉就行了
------解决方案--------------------
throws ==>:
------解决方案--------------------
throws 这貌似是java语法……
------解决方案--------------------
看错了,throws 换成 :(冒号)
------解决方案--------------------
1.throws IndexOutOfRangeException删掉
2.IndexOutOfRangeException不能继承,楼上都在卖萌吗
------解决方案--------------------
探讨

1.throws IndexOutOfRangeException删掉
2.IndexOutOfRangeException不能继承,楼上都在卖萌吗

------解决方案--------------------
探讨

引用:

1.throws IndexOutOfRangeException删掉
2.IndexOutOfRangeException不能继承,楼上都在卖萌吗

对的,是不能继承IndexOutOfRangeException类的

------解决方案--------------------
探讨
1.throws IndexOutOfRangeException删掉
2.IndexOutOfRangeException不能继承,楼上都在卖萌吗