Re: Try...Catch... Resume??



What is the method you are using to read the XML file ? IMO having a missing
optional element shouldn't raise an exception as this is not an unexpected
situation.

--
Patrice

"Rob R. Ainscough" <robains@xxxxxxxxxxx> a écrit dans le message de news:
OA1l0YuxGHA.4104@xxxxxxxxxxxxxxxxxxxxxxx
I was hoping to avoid using many Try ... Catch constructs repeatedly. What
I'm trying to accomplish is basically ignore an element error when reading
thru an XML file -- if the element isn't in the file just continue reading
and ignore -- this allows me to work with XML structures that change where
I'm only interested in certain parts of the XML file.

MSDN states that I can't use a Resume statement in a Try...Catch -- either
use one approach or the other. I like the Try..Catch construct, but I was
hoping that I wouldn't loose my Resume functionality. .NET still supports
the On Error ... Resume so I guess I'll have to use that for this
instances.

thanks, Rob.


"Michael" <Michael@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:543AFD2C-3B91-42C9-B750-53A6C11F6DCE@xxxxxxxxxxxxxxxx

Rob,

I think that if you change the scope of the try...catch you will find
that
you can accomplish what you are looking for. Take the following pseudo
code
for example...

Try
For x = 1 to 100
' Do something that causes an error occasionally.
Next
Catch Exception


Using the preceding exception handling you cannot return to the loop to
continue. But if you simply change it to:

For x = 1 to 100
Try
' Do something that causes an error occasionally.
Catch Exception
Next

You're code can continue to work on the loop. When you catch exceptions
you
want to keep it to the smallest scope possible and want to catch the most
specific exception possible. By this I mean, assume that you are using
File.Copy to copy a file. Looking in the MSDN documentation you can see
that
it can throw 8 different exception types. You may be tempted to catch
System.Exception just to have one catch block but with a little
forethought
you do not need to worry about all 8 of them. You can check the
arguments
that you pass in before to make sure that they are valid and eliminate
the
possibility of it throwing ArgumentException, ArgumentNullException,
DirectoryNotFoundException, FileNotFoundException, and
NotSupportedOption.
If you have checked for permissions or used code access security to
specify
your permissions you can avoid the UnuathorizedAccessException. Thus,
you
would just need to catch the IOException which you can not really plan
around
since you cannot know ahead of time if your hard drive is going to crash.

I hope this long winded answer is close to what you were looking for.

Michael
"Rob R. Ainscough" wrote:

In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything
similiar
when using Try...Catch -- so how can one resume the next statement when
an
error can be ignored?

Thanks, Rob.







.



Relevant Pages

  • Re: default namespace / Xmlvalidatingreader
    ... You dont get an exception in the case of the second file, ... validation warning should be thrown. ... XmlReader readerToUse = validatingReader; ...
    (microsoft.public.dotnet.xml)
  • Re: XmlValidatingReader / Default Namespace
    ... You dont get an exception in the case of the second file, ... validation warning should be thrown. ... XmlReader readerToUse = validatingReader; ...
    (microsoft.public.dotnet.xml)
  • Re: Xml validation exception only occurs outside debugger - VS 200
    ... I'm able to reproduce the problem on any Xml file (even ones produced by ... Could you attach the entire stack trace and message for the exception? ... outside the debugger I receive the following error: ...
    (microsoft.public.dotnet.xml)
  • Re: pocket pc emulator
    ... but i got FileNotFound exception.. ... this time i got directoryNotFound exception.. ... >> a text file or an xml file, ... > emulator. ...
    (microsoft.public.dotnet.framework.compactframework)
  • RE: Error when attaching multiple files (System.web.mail)
    ... Settings folder on your machine to the authenticated domain user account. ... Try to give permissions to ASPNET user account on the local folder where ... you are storing your attachments. ... > following exception. ...
    (microsoft.public.dotnet.framework.aspnet)