Visual Studio function to automatically create matching catch blocks for exceptions?

Let's say I have the following method in C #:

XslCompiledTransform myObject;

public void foo() {
  try {
    myObject.Transform(input, output);
  } catch (???) {
  }
}

Is there an option or functionality in Visual Studio 2012 that automatically generates all the blocks catchfor exceptions that may occur in XslCompiledTransform? How to "Create catch blocks"?

+4
source share
3 answers

No, there is no sensible way to automatically generate all catch blocks of all possible exceptions. But Visual Studio shows a list of related exceptions for calling the function, as shown below.

Visual Studio showed a related exception

+1
source

. , .

:

  • ArgumentNullException , , input/output null
  • IOException DirectoryNotFoundException/FileNotFoundException ,

, , . "log then re-throw", .


EDIT: , , . ( visualstudiogallery). , , Exception Hunter, RedGate, , . :

.NET 4.0 WPF , CLR , . , CLR . , , , , . , , . , .

+3

, , . , , .

Usually try to catch them at the highest logical level, where you are flexible enough in your application to make a wither decision throwor handle it somehow.

+2
source

Source: https://habr.com/ru/post/1526706/


All Articles