AddEntry and other APIs do not try own Exceptions

Nov 5, 2010 at 3:53 PM

Why APIs such "AddEntry" do no try own Exceptions?

If something goes wrong while I'm adding elements to a ZipFile, I would like to know what is the element that raise the Exception.

Now, instead I have to implement a my procedure to check the specific element in the "catch (...)"


Nov 5, 2010 at 5:14 PM

I'm having trouble with your English syntax.

I don't understand what you mean by "try own Exceptions". 

You're referring to a design decision in DotNetZip regarding exceptions, but I don't know exactly what the decision or behavior is.  Also I don't understand what problem this behavior causes you.


Nov 5, 2010 at 5:49 PM

"try API (of the ZipNet classes) own exception. Sorry for the mistake.

To clarify my idea I put here an example


   Using (Zip....)

      foreach (var o in list)
catch (Exception or ArgumentException or Exception of System NS)
    // do smt

If AddEntry raises an Exception I have to catch it as "System Exception" that doesn't tell me nothing about the object "o" I tried to put with AddEntry. 
So I have to do something like this:

catch (System.Exception....)
    foreach( var o in list)
        check what is the "o" object that has problem

    MessageBox.Show("The object is"+ o)

Instead, I would like something close to this:

catch (ZipNetException.DuplicatedItem ex)
    MessageBox.Show("The object probably is "+ e.Message)

As you can see, in this code I catch YOUR exception and not a generic system exception. 
With your (ZipNet) exception I could have the entry that raised the exception.

Yes I think is a design question.

I hope my idea is more clear now



Nov 5, 2010 at 8:33 PM

ok, it is becoming a little clearer.

I think what you are saying is that you would like to receive a exception that is specific to DotNetZip in case of a particular error or exception condition.

Can you tell me, what is the specific exceptional condition you are referring to?  what specific exception is raised currently by DotNetZip?  Can you show a stacktrace, please?   What specific exception would you like to receive?


Nov 5, 2010 at 9:05 PM

I make a Zip with contents and relative entry names. It could happen that some entries are duplicated. 

In this case I would like to receive an  Exception telling me the entry is already present. As the message of the Exception it could

have the name of the Entry I try to add. 


Monday morning I'm going to send you the stacktrace and the specific exception I get.


thanks a lot

Nov 7, 2010 at 1:32 PM

Thank you - send the stacktrace and we'll see if we can make some progress on that.

Nov 8, 2010 at 10:22 AM

here is the StackTrace

   in System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   in System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   in System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   in Ionic.Zip.ZipFile.InternalAddEntry(String name, ZipEntry entry)
   in Ionic.Zip.ZipFile._InternalAddEntry(ZipEntry ze)
   in Ionic.Zip.ZipFile.AddEntry(String entryName, Stream stream)
   in Ionic.Zip.ZipFile.AddEntry(String entryName, String content, Encoding encoding)
   in Ra....Sta.Logic.ProjectManager.SalvaProgetto(String nomeProgetto, List`1 listAg) in C:\Lavoro\Lavoro\...\Logic\ProjectManager.cs:riga 232


I catch the "System.ArgumentException".



Nov 9, 2010 at 4:13 PM

Ah, yes, the generic Dictionary throws System.ArgumentException when you try to add a duplicate key.

ok, now... what is the problem with that exception?   Can you tell me what you would propose as an alternative? Would you prefer to get something like Ionic.Zip.DuplicateZipEntryException ?

Let me think about that. 

Nov 9, 2010 at 5:15 PM


I would like to have Ionic.Zip.DuplicateZipEntryException and in the payload of the exception the name of the entry I tried to add.

catch (Ionic.Zip.DuplicateZipEntryException ex)
    MessageBox.Show("The object probably is "+ e.Message)

Nov 9, 2010 at 5:37 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 9, 2010 at 5:38 PM

ok Signor, I think that makes sense.

This feature won't be available until I build a new release.  I hope that will be soon, but no guarantees.