我正在学习C#,捕捉异常时遇到这样一个类InvariantException,问问高手,这个是系统的类么?我好像报错,说是找不到命名空间?

解决方案 »

  1.   

    你的程序是否引用了非系统的dll或者其他
      

  2.   

    没用到过,如过是如你所说我想你最好要用个using System.?
      

  3.   

    我是模仿阶段,写了一个关于栈的类,如下:
    using System;namespace testcmp
    {
    /// <summary>
    /// MyStack の概要の説明です。
    /// </summary>
    public class MyStack
    {
    public MyStack()
    {
    stack = new string[100];
    nextIndex = 0;
    }
    public string Pop(){
    return stack[--nextIndex];
    }
    public void Delete(int n){
    nextIndex -= n;
    }
    public void Push(string astring){
    stack[nextIndex++] = astring;
    }
    public string Top(){
    return stack[nextIndex-1];
    }
    private int nextIndex;
    private string[] stack;

    public void CheckInvariant(){
    if (!(nextIndex >=0 && nextIndex < stack.Length )){
    throw new InvariantException(
    "nextIndex out of the range:" + nextIndex + 
    "for stack length" + stack.Length 
    );
    }
    }
    }
    }
    因为我在学NUnit,所以写了一个小类,做作测试的。
    谢谢高手指教阿
      

  4.   

    InvalidValueException
    [This documentation is preliminary and subject to change.]The InvalidValueException class represents a non-fatal E_invalidValue runtime error that occurs during the execution of a UDDI method.The InvalidValueException class is derived from the Microsoft.Uddi.UddiException class.
      

  5.   

    Thanks for your answer!
    Could you say in detail and in chinese maybe better for me !
      

  6.   

    你需要去定义InvariantException这个类
      

  7.   

    你可以用ApplicationException来替换
      

  8.   

    恩,谢谢楼上的,我的确用ApplicationException来替换了一下,编译就通过了。
    不过能告诉我,它们之间有什么区别么?它是个系统类么?
      

  9.   

    “你需要去定义InvariantException这个类“
    就是说,这是个自定义的类咯?如果功能上也只是抛出异常信息的话,就没有必要重新定义,在这里花力气了,对么?
      

  10.   

    在MSDN中间输入InvariantException搜索看看能够得到结果吗?有就是,没有就是外部的
      

  11.   

    通常的自定义类都继承自ApplicationException。当然,自定义异常类也是抛出异常信息,但是你在编写自定义异常类时,
    可以让它抛出“特定的”“明确的”异常信息,所以不能说是白花力气。