简体   繁体   中英

Autocomplete try catch (not standard Exception)

Is there any shortcut for invoke auto-complete try catch block. But the main problem is I don't wan't to catch simple Exception but all Exceptions that can occur in selected piece of code.

For example:

    try
        {
            Directory.CreateDirectory("test");
        }
        catch (IOException)
        {
            // code
        }
        catch (UnauthorizedAccessException)
        {
            // code
        }
        .
        .
        .
        .

不,这是不可能的,因为没有什么可以告诉你方法可以引发哪些例外(文档除外,这并不总是准确的)。

I think you are asking about two things, 1. Throwing exception (autocomplete try catch block) 2. Use Exception class in catch block (for catching all exceptions).

Link below describs exception handling in C# in great details. And could answer your question in better way. http://www.codeproject.com/Articles/125470/Exception-Handling-for-C-Beginners

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