Skip to content

Commit 9e21b44

Browse files
committed
now throws an exception if not handled using delegates.
1 parent dbda102 commit 9e21b44

File tree

1 file changed

+65
-8
lines changed

1 file changed

+65
-8
lines changed

src/Core/FileSystemScanner.cs

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,58 @@ public bool ContinueRunning
286286
public delegate void FileFailureHandler(object sender, ScanFailureEventArgs e);
287287
#endregion
288288

289+
/// <summary>
290+
/// An exception encountered dutring scanning.
291+
/// </summary>
292+
#if !NETCF_1_0 && !NETCF_2_0
293+
[Serializable]
294+
#endif
295+
public class ScanException : SharpZipBaseException
296+
{
297+
/// <summary>
298+
/// Initializes a new instance of the <see cref="ScanException"/> class.
299+
/// </summary>
300+
public ScanException()
301+
{
302+
}
303+
304+
/// <summary>
305+
/// Initializes a new instance of the <see cref="ScanException"/> class.
306+
/// </summary>
307+
/// <param name="message">The message.</param>
308+
public ScanException(string message)
309+
: base(message)
310+
{
311+
}
312+
313+
/// <summary>
314+
/// Initializes a new instance of the <see cref="ScanException"/> class.
315+
/// </summary>
316+
/// <param name="message">The message.</param>
317+
/// <param name="innerException">The inner exception.</param>
318+
public ScanException(string message, Exception innerException)
319+
: base(message, innerException)
320+
{
321+
}
322+
323+
#if !NETCF_1_0 && !NETCF_2_0
324+
/// <summary>
325+
/// Initializes a new instance of the <see cref="ScanException"/> class.
326+
/// </summary>
327+
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
328+
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
329+
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
330+
/// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
331+
public ScanException(
332+
System.Runtime.Serialization.SerializationInfo info,
333+
System.Runtime.Serialization.StreamingContext context
334+
)
335+
: base(info, context)
336+
{
337+
}
338+
#endif
339+
}
340+
289341
/// <summary>
290342
/// FileSystemScanner provides facilities scanning of files and directories.
291343
/// </summary>
@@ -367,11 +419,14 @@ public FileSystemScanner(IScanFilter fileFilter, IScanFilter directoryFilter)
367419
/// <param name="e">The exception detected.</param>
368420
void OnDirectoryFailure(string directory, Exception e)
369421
{
370-
if ( DirectoryFailure == null ) {
371-
alive_ = false;
372-
} else {
422+
DirectoryFailureHandler handler = DirectoryFailure;
423+
if (handler == null) {
424+
alive_ = false;
425+
throw new ScanException("Directory scan failure", e);
426+
}
427+
else {
373428
ScanFailureEventArgs args = new ScanFailureEventArgs(directory, e);
374-
DirectoryFailure(this, args);
429+
handler(this, args);
375430
alive_ = args.ContinueRunning;
376431
}
377432
}
@@ -383,8 +438,10 @@ void OnDirectoryFailure(string directory, Exception e)
383438
/// <param name="e">The exception detected.</param>
384439
void OnFileFailure(string file, Exception e)
385440
{
386-
if ( FileFailure == null ) {
387-
alive_ = false;
441+
FileFailureHandler handler = FileFailure;
442+
if ( handler == null ) {
443+
alive_ = false;
444+
throw new ScanException("File failure", e);
388445
} else {
389446
ScanFailureEventArgs args = new ScanFailureEventArgs(file, e);
390447
FileFailure(this, args);
@@ -483,7 +540,7 @@ void ScanDir(string directory, bool recurse)
483540
}
484541
}
485542
catch (Exception e) {
486-
OnDirectoryFailure(directory, e);
543+
OnDirectoryFailure(directory, e);
487544
}
488545

489546
if ( alive_ && recurse ) {
@@ -499,7 +556,7 @@ void ScanDir(string directory, bool recurse)
499556
}
500557
}
501558
catch (Exception e) {
502-
OnDirectoryFailure(directory, e);
559+
OnDirectoryFailure(directory, e);
503560
}
504561
}
505562
}

0 commit comments

Comments
 (0)