简体   繁体   中英

Where to find information on exceptions thrown by classes and methods?

I am trying to add more specific error handling to my c# app, but I am finding it hard to track down what exceptions are thrown by classes and method. Is there a way through visual studio 2010 to find this info, or maybe an exception list?

Just find the class/method you are interested in on MSDN.

For example, look at this page for the Dictionary.Remove Method . If the method throws an Exception (like this one), you can get the information for the Exceptions section of the page.

If you are talking about .Net framework methods, they are documented in the hover over help. You will see Exceptions: . Or you can see it in the object browser Ctrl+W, J as well. Or press F1 over a function to go to MSDN help, where they are documented in detail.

如果您允许抛出异常,则应该能够在“管理工具”的“事件查看器”中查看异常详细信息。

You can find specific uses of a particular exception, but there is no complete listing of all exceptions any method might throw.

Consider the following method:

  public void SomeMethod()
  {
       SomeObject x = null;
       x.SomeMethod(); // NullReferenceException

       File.Open("SomePath", FileMode.CreateNew); // Any number of File Exceptions potentially

       throw new CustomException();
  };

How would a code analyzer be able to determine which potential exceptions there were?

If you're looking for information on a specific class, I'd check the documentation for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM