473,490 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stopping error message in VB .NET

Hello

I'm a newbie in VB .NET and I'd like to accomplish a (I think) very
simple task.

What I want to do is throw an error message to the user whenever
something happens. The main point is that the message must stop the
code execution, but it sholud not close the application nor show the
classical exception window (the one with JIT compiler information).

That is, I'd like to make something like
Dim L_XMLConfigurationFile As XmlDocument = New XmlDocument

Try
L_XMLConfigurationFile.Load("c:\temp\TestFile.xml" )
Catch ex As Exception
MyErrorFunction("The file <TestFile.xml> does not
exists.")
End Try

MessageBox.Show("We got there...")
and I want to get an error window telling the user that the file does
not exists, but I must not allow to continue the program execution.
That is, the program should never get to the MessageBox.Show("We got
there...") line if the file does not exists.

The exception handler mechanism shows a window that allows the user to
continue execution, so it does not fit my needs.

Some languages have an ERROR function that stops the execution where
it is called, and I want just that.

Any ideas?
Thanks,

Toni
Jul 22 '05 #1
8 2023

"Toni" <to************@gmail.com> wrote in message
news:1d**************************@posting.google.c om...
Hello

I'm a newbie in VB .NET and I'd like to accomplish a (I think) very
simple task.

What I want to do is throw an error message to the user whenever
something happens. The main point is that the message must stop the
code execution, but it sholud not close the application nor show the
classical exception window (the one with JIT compiler information).

That is, I'd like to make something like
Dim L_XMLConfigurationFile As XmlDocument = New XmlDocument

Try
L_XMLConfigurationFile.Load("c:\temp\TestFile.xml" )
Catch ex As Exception
MyErrorFunction("The file <TestFile.xml> does not
exists.")
End Try

MessageBox.Show("We got there...")
and I want to get an error window telling the user that the file does
not exists, but I must not allow to continue the program execution.
That is, the program should never get to the MessageBox.Show("We got
there...") line if the file does not exists.

The exception handler mechanism shows a window that allows the user to
continue execution, so it does not fit my needs.

Some languages have an ERROR function that stops the execution where
it is called, and I want just that.

Any ideas?
Thanks,

Toni


As the last statement in your MyErrorFunction(), which you are calling if
the attempt to load the config file fails, try this:

Application.Exit()

Going back to your question, you appear to make contradictory statements:
"The main point is that the message must stop the code execution, but it
should not close the application..."

and

"...and I want to get an error window telling the user that the file does
not exists, but I must not allow to continue the program execution."

If you do wish to "not allow to continue program execution", then
Application.Exit() is for you.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Jul 22 '05 #2
You could put the code in the try block. It won't get executed if the catch
is invoked before it is hit.

You could also just exit the Sub or Function using: Exit Sub or Exit
Function.

When you say you want the program to stop I'm guessing you mean you want
that particular funtion to stop, but that the user may choose to try
something else...?

Otherwise, use the Application.Exit as noted in a previous post.

Jerry
"Toni" <to************@gmail.com> wrote in message
news:1d**************************@posting.google.c om...
Hello

I'm a newbie in VB .NET and I'd like to accomplish a (I think) very
simple task.

What I want to do is throw an error message to the user whenever
something happens. The main point is that the message must stop the
code execution, but it sholud not close the application nor show the
classical exception window (the one with JIT compiler information).

That is, I'd like to make something like
Dim L_XMLConfigurationFile As XmlDocument = New XmlDocument

Try
L_XMLConfigurationFile.Load("c:\temp\TestFile.xml" )
Catch ex As Exception
MyErrorFunction("The file <TestFile.xml> does not
exists.")
End Try

MessageBox.Show("We got there...")
and I want to get an error window telling the user that the file does
not exists, but I must not allow to continue the program execution.
That is, the program should never get to the MessageBox.Show("We got
there...") line if the file does not exists.

The exception handler mechanism shows a window that allows the user to
continue execution, so it does not fit my needs.

Some languages have an ERROR function that stops the execution where
it is called, and I want just that.

Any ideas?
Thanks,

Toni

Jul 22 '05 #3


Jerry Camel ha escrito:
You could put the code in the try block. It won't get executed if the catch
is invoked before it is hit.

You could also just exit the Sub or Function using: Exit Sub or Exit
Function.

When you say you want the program to stop I'm guessing you mean you want
that particular funtion to stop, but that the user may choose to try
something else...?

Otherwise, use the Application.Exit as noted in a previous post.

Jerry


Hello
When you say you want the program to stop I'm guessing you mean you want
that particular funtion to stop, but that the user may choose to try
something else...?


Yes, I want the user may choose to try something else (maybe in the
same form where the error happened), so I don't want to close the
application.

I can't use the Exit Function or Exit Sub way because that wolud exit
the current function, but the main execution thread will continue from
there. And I want the main program execution to stop.

I'll try the Application.Exit route. Thanks!
Toni

Jul 22 '05 #4


to************@gmail.com ha escrito:
Jerry Camel ha escrito:
You could put the code in the try block. It won't get executed if the catch
is invoked before it is hit.

You could also just exit the Sub or Function using: Exit Sub or Exit
Function.

When you say you want the program to stop I'm guessing you mean you want
that particular funtion to stop, but that the user may choose to try
something else...?

Otherwise, use the Application.Exit as noted in a previous post.

Jerry


Hello
When you say you want the program to stop I'm guessing you mean you want
that particular funtion to stop, but that the user may choose to try
something else...?


Yes, I want the user may choose to try something else (maybe in the
same form where the error happened), so I don't want to close the
application.

I can't use the Exit Function or Exit Sub way because that wolud exit
the current function, but the main execution thread will continue from
there. And I want the main program execution to stop.

I'll try the Application.Exit route. Thanks!
Toni

Hi

Well, the Application.Exit line effectively closes my application, so
it is not for me. I want the user to remain into the program window
where the error arose.

The nearest thing I reached is simply don't doing nothing. That is, I
simply write the code without using the try/catch thing. If there is
an error the system throws an undhandeld exception (the dialog box with
a red cross in it) with some information about the error. The user can
hit the Continue button and the program won't close; the user remains
where he was before the error.

I'd like to have control on the text that the dialog shows with the
exception, and make the code execution stop there in order to let the
user try something different.
Toni

Jul 22 '05 #5

<to************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Well, the Application.Exit line effectively closes my application, so
it is not for me. I want the user to remain into the program window
where the error arose.

The nearest thing I reached is simply don't doing nothing. That is, I
simply write the code without using the try/catch thing. If there is
an error the system throws an undhandeld exception (the dialog box with
a red cross in it) with some information about the error. The user can
hit the Continue button and the program won't close; the user remains
where he was before the error.

I'd like to have control on the text that the dialog shows with the
exception, and make the code execution stop there in order to let the
user try something different.
Toni

Doing nothing about exceptions is not good design, and if you leave it at
that, your program will likely just crash when run outside the IDE. The
dialog you are seeing with the Continue button as a choice is a product of
the IDE, IIRC, and once your product is deployed, your users won't get that
dialog.
(This from recollection and subject to correction).

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Jul 22 '05 #6
You could wrap some of the code in a While statement and just keep looping
until you are successful.

I think you may need to review the architecture of your application. If you
have a process that can fail, but a user should be able to retry, that
process should be encapsulated in it's own procedure. The procedure should
return a success or failure code and the code that calls the procedure can
act on that by running it again, if necessary. (Well, that's one way to
handle it.)

With the event driven arhictecture, you can't really just stop in the middle
of a handler and wait for the user to try something new. You have to set it
up so that if you fail, you end up back where you started and wait for the
same event that triggered the failure. (Button click or whatever...)

Maybe if you posted mor of the code I can get a better idea of what you are
trying to do...

Jerry

"Jerry Camel" <rl*****@msn.com> wrote in message
news:O6****************@tk2msftngp13.phx.gbl...
You could put the code in the try block. It won't get executed if the catch is invoked before it is hit.

You could also just exit the Sub or Function using: Exit Sub or Exit
Function.

When you say you want the program to stop I'm guessing you mean you want
that particular funtion to stop, but that the user may choose to try
something else...?

Otherwise, use the Application.Exit as noted in a previous post.

Jerry
"Toni" <to************@gmail.com> wrote in message
news:1d**************************@posting.google.c om...
Hello

I'm a newbie in VB .NET and I'd like to accomplish a (I think) very
simple task.

What I want to do is throw an error message to the user whenever
something happens. The main point is that the message must stop the
code execution, but it sholud not close the application nor show the
classical exception window (the one with JIT compiler information).

That is, I'd like to make something like
Dim L_XMLConfigurationFile As XmlDocument = New XmlDocument

Try
L_XMLConfigurationFile.Load("c:\temp\TestFile.xml" )
Catch ex As Exception
MyErrorFunction("The file <TestFile.xml> does not
exists.")
End Try

MessageBox.Show("We got there...")
and I want to get an error window telling the user that the file does
not exists, but I must not allow to continue the program execution.
That is, the program should never get to the MessageBox.Show("We got
there...") line if the file does not exists.

The exception handler mechanism shows a window that allows the user to
continue execution, so it does not fit my needs.

Some languages have an ERROR function that stops the execution where
it is called, and I want just that.

Any ideas?
Thanks,

Toni


Jul 22 '05 #7
Hi

What I am looking for is something very common to do in ERP
applications.
For instance, in an ERP I can write a function with something like
this:

<code>
get_customer_information();
get_account_information();
post_invoice();
message("OK");
</code>

This will read some data from the customer and account tables and will
write some data for posting the invoice.

If there is some problem reading the customer table, I'll throw an
error and I'm sure that the code execution will not reach the
post_invoice() function. For instance,

function get_customer_information(){
...
...

if customer.name = "" then
error("Customer is nameless!"); // <--- This is the function I'd
like

...

}
Of course I could code my functions in order to so something like

if get_customer_information() then
if get_account_information() then
if post_invoice() then
message("OK");
But this forces me to keep track of errors and exit boolean values in
every function, which is cumbersome when you have a fairly big
application. I am used to work with really big ERP systems where that
is simply not an option.

What I'm trying is to adapt my programming ideas from the ERP to VB
..NET, if it is possible.

Thanks!
Toni

Jul 22 '05 #8
What if you used a global error indicator, maybe called ErrorOccurred...

If any of the routines encounter an error, they pop up a message and set
ErrorOccurred = True in the Catch block.

Your parent routine calls the subs like this:

If Not ErrorOccurred Then Get_Customer_Information()
If Not ErrorOccured Then Get_Account_Information()
If Not ErrorOccured Then Post_Invoice()

Then at whatever point the error occurs, the rest of the routine is skipped
and your back where you started before this guy was called.

Other than this, I'm not sure I really understand what's missing.

Jerry
<to************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi

What I am looking for is something very common to do in ERP
applications.
For instance, in an ERP I can write a function with something like
this:

<code>
get_customer_information();
get_account_information();
post_invoice();
message("OK");
</code>

This will read some data from the customer and account tables and will
write some data for posting the invoice.

If there is some problem reading the customer table, I'll throw an
error and I'm sure that the code execution will not reach the
post_invoice() function. For instance,

function get_customer_information(){
...
...

if customer.name = "" then
error("Customer is nameless!"); // <--- This is the function I'd
like

...

}
Of course I could code my functions in order to so something like

if get_customer_information() then
if get_account_information() then
if post_invoice() then
message("OK");
But this forces me to keep track of errors and exit boolean values in
every function, which is cumbersome when you have a fairly big
application. I am used to work with really big ERP systems where that
is simply not an option.

What I'm trying is to adapt my programming ideas from the ERP to VB
.NET, if it is possible.

Thanks!
Toni

Jul 22 '05 #9

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

Similar topics

1
7262
by: BKM | last post by:
I'm using a VB6 WebBrowser control to get info from various web pages and, occasionally, my program stops when it finds a script error on the page. It won't resume until I click 'Yes' or 'No' on...
4
15852
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
5
3486
by: Eric Dan | last post by:
If I would like to stop an ASP.NET application after some initialization error during the "Application_Start" event (which I have caught within a catch clause) – what is the right way to do it?...
7
261
by: Toni | last post by:
Hello I'm a newbie in VB .NET and I'd like to accomplish a (I think) very simple task. What I want to do is throw an error message to the user whenever something happens. The main point is...
2
2231
by: matteo | last post by:
Hi everyboby, i wrote a c# service that every XXX minute launch a working thread on timer events, something like this: private void timer_Elapsed ( object status ) { // Worker thread...
5
17356
by: chris.hearson | last post by:
How do I programmatically prevent a service from stopping? I want to be able to keep my service running (started), under certain conditions, when a user tries to stop it. I have tried throwing an...
4
1561
by: brian | last post by:
i broke down where i think the problems areas would be. any help would be greatly appreciated. where the file is called <script type="text/javascript" src="k.js"> </script> the beginning...
2
3329
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
10
2443
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following three files. 1. Users.aspx is a webpage that uses the <asp:ObjectDataSourcecontrol to populate a simple <asp:ListBoxcontrol. 2. The UserDetails.cs file creates a Namespace...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6974
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
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.