473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How solve this IF Then problem?

Hello,

I need to load a XML file and call a function if it wasn't possible.
I have this:

Sub Build_RSS()

Dim news As New XmlDocument()
If news.Load("http://www.domain.com/news.rss") Then
' Do Actions
Else
Display_Error("File not Found")
End If

End Sub

However the page gets an error when the URL of the file is wrong instead
of displaying my custom error. How can I solve this?

Thanks,
Miguel

Nov 19 '05 #1
4 1142
Hi,

If you look at the documentation for then XmlDocument.Load() method you will
notice that it is a Sub and does not return a value. If there are any errors
it will throw an exception. Rather than using an if statement you should
catch the exceptions thrown by the method and deal with the exception
appropriately.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hello,

I need to load a XML file and call a function if it wasn't possible.
I have this:

Sub Build_RSS()

Dim news As New XmlDocument()
If news.Load("http://www.domain.com/news.rss") Then
' Do Actions
Else
Display_Error("File not Found")
End If

End Sub

However the page gets an error when the URL of the file is wrong instead
of displaying my custom error. How can I solve this?

Thanks,
Miguel

Nov 19 '05 #2
Hi,

You were right. I did as follows:
Sub Build_RSS()
Try
news.Load("http://www.domain.com/news.rss")
Catch ex As Exception
Display_Error("File not Found")
End Try
End Sub

It works fine. There is only one problem: I have the code to build the
news system after this. How can I interrupt Build_RSS() after calling
Display_Error?

Thank You,
Miguel

"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:ch*************@hotmail.com:
Hi,

If you look at the documentation for then XmlDocument.Load() method you will
notice that it is a Sub and does not return a value. If there are any errors
it will throw an exception. Rather than using an if statement you should
catch the exceptions thrown by the method and deal with the exception
appropriately.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hello,

I need to load a XML file and call a function if it wasn't possible.
I have this:

Sub Build_RSS()

Dim news As New XmlDocument()
If news.Load("http://www.domain.com/news.rss") Then
' Do Actions
Else
Display_Error("File not Found")
End If

End Sub

However the page gets an error when the URL of the file is wrong instead
of displaying my custom error. How can I solve this?

Thanks,
Miguel


Nov 19 '05 #3
Hi,

Sub Build_RSS()
Try
news.Load("http://www.domain.com/news.rss")
' Do the work here ... if the Load thows an exception then this is
skipped
Catch ex As Exception
Display_Error("File not Found")
End Try
End Sub

Note that you should be more specific about the exception, an exception
could be raised for a number
of reasons other than file not being found.

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:uL**************@TK2MSFTNGP10.phx.gbl...
Hi,

You were right. I did as follows:
Sub Build_RSS()
Try
news.Load("http://www.domain.com/news.rss")
Catch ex As Exception
Display_Error("File not Found")
End Try
End Sub

It works fine. There is only one problem: I have the code to build the
news system after this. How can I interrupt Build_RSS() after calling
Display_Error?

Thank You,
Miguel

"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:ch*************@hotmail.com:
Hi,

If you look at the documentation for then XmlDocument.Load() method you will notice that it is a Sub and does not return a value. If there are any errors it will throw an exception. Rather than using an if statement you should
catch the exceptions thrown by the method and deal with the exception
appropriately.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hello,

I need to load a XML file and call a function if it wasn't possible.
I have this:

Sub Build_RSS()

Dim news As New XmlDocument()
If news.Load("http://www.domain.com/news.rss") Then
' Do Actions
Else
Display_Error("File not Found")
End If

End Sub

However the page gets an error when the URL of the file is wrong instead of displaying my custom error. How can I solve this?

Thanks,
Miguel

Nov 19 '05 #4
Hello
In your case it is better to use:
Catch ex As FileNotFoundException
Regards

"Chris Taylor" wrote:
Hi,

Sub Build_RSS()
Try
news.Load("http://www.domain.com/news.rss")
' Do the work here ... if the Load thows an exception then this is
skipped
Catch ex As Exception
Display_Error("File not Found")
End Try
End Sub

Note that you should be more specific about the exception, an exception
could be raised for a number
of reasons other than file not being found.

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:uL**************@TK2MSFTNGP10.phx.gbl...
Hi,

You were right. I did as follows:
Sub Build_RSS()
Try
news.Load("http://www.domain.com/news.rss")
Catch ex As Exception
Display_Error("File not Found")
End Try
End Sub

It works fine. There is only one problem: I have the code to build the
news system after this. How can I interrupt Build_RSS() after calling
Display_Error?

Thank You,
Miguel

"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:ch*************@hotmail.com:
Hi,

If you look at the documentation for then XmlDocument.Load() method you will notice that it is a Sub and does not return a value. If there are any errors it will throw an exception. Rather than using an if statement you should
catch the exceptions thrown by the method and deal with the exception
appropriately.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...

> Hello,
>
> I need to load a XML file and call a function if it wasn't possible.
> I have this:
>
> Sub Build_RSS()
>
> Dim news As New XmlDocument()
> If news.Load("http://www.domain.com/news.rss") Then
> ' Do Actions
> Else
> Display_Error("File not Found")
> End If
>
> End Sub
>
> However the page gets an error when the URL of the file is wrong instead > of displaying my custom error. How can I solve this?
>
> Thanks,
> Miguel
>


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BVM | last post by:
Hi, All: I have this error. It seems execution time is too long. Actually the execution time is about 30 seconds(I tested in Query analyzer). How do I solve this problem? ...
3
by: Alex | last post by:
Hi, I have a problem involving some design issue. I have two unrelated (that is, they do not derive from the same base) classes: ClassA ClassB Both have a quite similar interface, so they can...
7
by: Shapper | last post by:
Hello, I have an ASP:ImageButton where I want to call a function and pass a string: OnClick="Change_Photo("John")" I am having problems with "". I tried
6
by: Federico | last post by:
Hi, this is what I can do: - Create new solutions using VS.Net ASP.Net - Save the solutions, build the solution, view in browser with the solution still open. But, once I close the solution, I...
0
by: Jitesh | last post by:
I am facing a problem in webservice, I want to know what will be the exact procedure to solve the problem............. What I want to do............ I have a table named order in SQL Server....
27
by: John Salerno | last post by:
Ok, here's a problem I've sort of assigned to myself for fun, but it's turning out to be quite a pain to wrap my mind around. It's from a puzzle game. It will help if you look at this image: ...
8
by: vj | last post by:
Hi all, I want to solve the two equations u*tan(u)=w and u^2 + w^2=V^2, where V is a known constant, and u and w are the two unknowns to be determined. Please can someone suggest me how to...
1
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. ...
17
by: Michael Reichenbach | last post by:
Here is the example code. int main(int argc, char *argv) { string Result; WIN32_FIND_DATA daten; HANDLE h = FindFirstFile(TEXT("c://test"), &daten); system("PAUSE"); return EXIT_SUCCESS; }
2
by: itsvineeth209 | last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc. U had created...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.