|
1 | 1 | using System;
|
2 | 2 | using System.ComponentModel;
|
3 |
| -//using System.Diagnostics; |
4 | 3 |
|
5 |
| -namespace Win32Exception_CS |
6 |
| -{ |
7 |
| - class Class1 { |
8 |
| - static void Main(string[] args) { |
| 4 | +namespace Win32Exception_CS; |
9 | 5 |
|
10 |
| - //<snippet1> |
11 |
| - try { |
12 |
| - System.Diagnostics.Process myProc = new System.Diagnostics.Process(); |
13 |
| - myProc.StartInfo.FileName = "c:\nonexist.exe"; //Attempting to start a non-existing executable |
14 |
| - myProc.Start(); //Start the application and assign it to the process component. |
15 |
| - } |
16 |
| - catch(Win32Exception w) { |
17 |
| - Console.WriteLine(w.Message); |
18 |
| - Console.WriteLine(w.ErrorCode.ToString()); |
19 |
| - Console.WriteLine(w.NativeErrorCode.ToString()); |
20 |
| - Console.WriteLine(w.StackTrace); |
21 |
| - Console.WriteLine(w.Source); |
22 |
| - Exception e=w.GetBaseException(); |
23 |
| - Console.WriteLine(e.Message); |
24 |
| - } |
25 |
| - //</snippet1> |
26 |
| - } |
| 6 | +class Class1 |
| 7 | +{ |
| 8 | + static void Main(string[] args) |
| 9 | + { |
| 10 | + //<snippet1> |
| 11 | + try |
| 12 | + { |
| 13 | + System.Diagnostics.Process myProc = new(); |
| 14 | + myProc.StartInfo.FileName = @"c:\nonexist.exe"; // Attempt to start a non-existent executable |
| 15 | + myProc.Start(); |
| 16 | + } |
| 17 | + catch (Win32Exception w) |
| 18 | + { |
| 19 | + Console.WriteLine(w.Message); |
| 20 | + Console.WriteLine(w.ErrorCode.ToString()); |
| 21 | + Console.WriteLine(w.NativeErrorCode.ToString()); |
| 22 | + Console.WriteLine(w.StackTrace); |
| 23 | + Console.WriteLine(w.Source); |
| 24 | + Exception e = w.GetBaseException(); |
| 25 | + Console.WriteLine(e.Message); |
| 26 | + } |
| 27 | + //</snippet1> |
27 | 28 | }
|
28 | 29 | }
|
0 commit comments