Example
using System; using System.IO; using System.Security.Permissions; namespace Samples { public class UnauthorizedAccessExceptionConstructor { public static void Main() { try { string s = "readonly.txt"; FileStream fs = File.OpenWrite(s); } catch(UnauthorizedAccessException e) { Console.WriteLine("Exception: {0}", e); } } } }
Exception: System.UnauthorizedAccessException: Access to the path "C:\Books\BCL\Samples\System\UnauthorizedAccessException\readonly.txt" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String ...
Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.