New test.
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / UnixIOException.cs
index dcc32cc51b052578552ad5aaa666783fe1e80ff9..923e7aa08b62436972229546b2e63bfc8e5bb1c8 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //   Jonathan Pryor (jonpryor@vt.edu)
 //
-// (C) 2004 Jonathan Pryor
+// (C) 2004-2005 Jonathan Pryor
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -37,44 +37,46 @@ namespace Mono.Unix {
        [Serializable]
        public class UnixIOException : IOException
        {
+               private int errno;
+
                public UnixIOException ()
                        : this (Marshal.GetLastWin32Error())
                {}
                
-               public UnixIOException (int error)
+               public UnixIOException (int errno)
+                       : base (GetMessage (Native.NativeConvert.ToErrno (errno)))
                {
-                       this.error = error;
+                       this.errno = errno;
                }
                
-               public UnixIOException (int error, Exception inner)
-                       : base ("Unix-generated exception", inner)
+               public UnixIOException (int errno, Exception inner)
+                       : base (GetMessage (Native.NativeConvert.ToErrno (errno)), inner)
                {
-                       this.error = error;
+                       this.errno = errno;
                }
 
-               [Obsolete ("Use UnixIOException (Mono.Unix.Native.Errno) constructor")]
-               public UnixIOException (Error error)
+               public UnixIOException (Native.Errno errno)
+                       : base (GetMessage (errno))
                {
-                       this.error = UnixConvert.FromError (error);
+                       this.errno = Native.NativeConvert.FromErrno (errno);
                }
 
-               [Obsolete ("Use UnixIOException (Mono.Unix.Native.Errno, System.Exception) constructor")]
-               public UnixIOException (Error error, Exception inner)
-                       : base ("Unix-generated exception", inner)
+               public UnixIOException (Native.Errno errno, Exception inner)
+                       : base (GetMessage (errno), inner)
                {
-                       this.error = UnixConvert.FromError (error);
+                       this.errno = Native.NativeConvert.FromErrno (errno);
                }
 
-               public UnixIOException (Native.Errno error)
+               public UnixIOException (string message)
+                       : base (message)
                {
-                       this.error = Native.NativeConvert.FromErrno (error);
+                       this.errno = 0;
                }
 
-               [Obsolete ("Use UnixIOException (Mono.Unix.Native.Errno, System.Exception) constructor")]
-               public UnixIOException (Native.Errno error, Exception inner)
-                       : base ("Unix-generated exception", inner)
+               public UnixIOException (string message, Exception inner)
+                       : base (message, inner)
                {
-                       this.error = Native.NativeConvert.FromErrno (error);
+                       this.errno = 0;
                }
 
                protected UnixIOException (SerializationInfo info, StreamingContext context)
@@ -83,19 +85,18 @@ namespace Mono.Unix {
                }
                
                public int NativeErrorCode {
-                       get {return error;}
+                       get {return errno;}
                }
                
-               [Obsolete ("The type of this property will change in the next release")]
-               public Error ErrorCode {
-                       get {return UnixConvert.ToError (error);}
+               public Native.Errno ErrorCode {
+                       get {return Native.NativeConvert.ToErrno (errno);}
                }
 
-               private int error;
-
-               public override string ToString ()
+               private static string GetMessage (Native.Errno errno)
                {
-                       return UnixMarshal.GetErrorDescription (ErrorCode);
+                       return string.Format ("{0} [{1}].",
+                                       UnixMarshal.GetErrorDescription (errno),
+                                       errno);
                }
        }
 }