1- using System ;
2- #if NETFRAMEWORK
3- using System . Runtime . Serialization ;
4- #endif // NETFRAMEWORK
1+ #nullable enable
2+ using System ;
3+
4+ using Renci . SshNet . Sftp ;
55
66namespace Renci . SshNet . Common
77{
@@ -10,47 +10,82 @@ namespace Renci.SshNet.Common
1010 /// </summary>
1111#if NETFRAMEWORK
1212 [ Serializable ]
13- #endif // NETFRAMEWORK
14- public class SftpPathNotFoundException : SshException
13+ #endif
14+ public class SftpPathNotFoundException : SftpException
1515 {
16+ private const StatusCode Code = StatusCode . NoSuchFile ;
17+
18+ /// <summary>
19+ /// Gets the path that cannot be found.
20+ /// </summary>
21+ /// <value>
22+ /// The path that cannot be found, or <see langword="null"/> if no path was
23+ /// passed to the constructor for this instance.
24+ /// </value>
25+ public string ? Path { get ; }
26+
1627 /// <summary>
1728 /// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
1829 /// </summary>
1930 public SftpPathNotFoundException ( )
31+ : this ( message : null , path : null , innerException : null )
2032 {
2133 }
2234
2335 /// <summary>
2436 /// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
2537 /// </summary>
26- /// <param name="message">The message.< /param>
27- public SftpPathNotFoundException ( string message )
28- : base ( message )
38+ /// <inheritdoc cref="Exception(string)" path=" /param"/ >
39+ public SftpPathNotFoundException ( string ? message )
40+ : this ( message , path : null , innerException : null )
2941 {
3042 }
3143
3244 /// <summary>
3345 /// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
3446 /// </summary>
35- /// <param name="message">The message.</param>
36- /// <param name="innerException">The inner exception.</param>
37- public SftpPathNotFoundException ( string message , Exception innerException )
38- : base ( message , innerException )
47+ /// <inheritdoc cref="Exception(string)" path="/param"/>
48+ public SftpPathNotFoundException ( string ? message , string ? path )
49+ : this ( message , path , innerException : null )
3950 {
4051 }
4152
42- #if NETFRAMEWORK
4353 /// <summary>
4454 /// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
4555 /// </summary>
46- /// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
47- /// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
48- /// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <see langword="null"/>.</exception>
49- /// <exception cref="SerializationException">The class name is <see langword="null"/> or <see cref="Exception.HResult"/> is zero (0). </exception>
50- protected SftpPathNotFoundException ( SerializationInfo info , StreamingContext context )
56+ /// <inheritdoc cref="Exception(string, Exception)" path="/param"/>
57+ public SftpPathNotFoundException ( string ? message , Exception ? innerException )
58+ : this ( message , path : null , innerException )
59+ {
60+ }
61+
62+ /// <summary>
63+ /// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
64+ /// </summary>
65+ /// <param name="message">The error message that explains the reason for the exception.</param>
66+ /// <param name="path">The path that cannot be found.</param>
67+ /// <param name="innerException">The exception that is the cause of the current exception.</param>
68+ public SftpPathNotFoundException ( string ? message , string ? path , Exception ? innerException )
69+ : base ( Code , string . IsNullOrEmpty ( message ) ? GetDefaultMessage ( path ) : message , innerException )
70+ {
71+ Path = path ;
72+ }
73+
74+ private static string GetDefaultMessage ( string ? path )
75+ {
76+ var message = GetDefaultMessage ( Code ) ;
77+
78+ return path is not null
79+ ? $ "{ message } Path: '{ path } '."
80+ : message ;
81+ }
82+
83+ #if NETFRAMEWORK
84+ /// <inheritdoc/>
85+ protected SftpPathNotFoundException ( System . Runtime . Serialization . SerializationInfo info , System . Runtime . Serialization . StreamingContext context )
5186 : base ( info , context )
5287 {
5388 }
54- #endif // NETFRAMEWORK
89+ #endif
5590 }
5691}
0 commit comments