Exception handling in SevenZipExtractor class

Feb 8, 2011 at 9:03 PM

Hello

I try to extract files with the SevenZipExtractor class.
After specifying all needed parameters, I start the extraction process with the BeginExtractArchive()-Method. The extraction thread is created, the WinForms-GUI is not locked and everything works perfect (handlers, skipping of existing files e.g.) with valid archives.
But if there is a corrupt file or a wrong inserted password, an exception is thrown, when extracting is finished.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> SevenZip.ExtractionFailedException: Could not extract files! Message: File is corrupted. Data error has occured.
   at static Object System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at Object System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at Object System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at static void SevenZip.SevenZipBase.AsyncCallbackMethod(IAsyncResult ar)
   at IMessage System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)
   at IMessageCtrl System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
   at void System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()
   at static void System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
   at static void System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at static void System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at void System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at static Boolean System.Threading.ThreadPoolWorkQueue.Dispatch()
   at static Boolean System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

The problem is, that I have no clue, how I catch this exception. A try-catch container around BeginExtractArchive() or the whole creation of the SevenZipExtractor object is not working. Like I understood it, it is the asynchronous thread which is crashing.
And before I’m messing around with general thread exceptions handling, I would like to ask here.

How can I catch such exceptions? And above all, at which point in the code?
Sadly, I found no example, how the SevenZipException-Class, or exception handling of SevenZipSharp generally is used.

Thanks a lot.

Greetings,
Rabanti