473,398 Members | 2,343 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,398 software developers and data experts.

Recovering from error

Hi

I have a button which calls a method which in turn calls another method,
which in turn calls another method. Let's say in the third method an error
occurs and it is no longer possible to continue, how can I dump everything
and come out of everything waiting for the user to press the button again to
do the process again?

Thanks

Regards
Jun 27 '08 #1
6 827

"John" <in**@nospam.infovis.co.ukwrote in message
news:e5**************@TK2MSFTNGP02.phx.gbl...
Hi

I have a button which calls a method which in turn calls another method,
which in turn calls another method. Let's say in the third method an error
occurs and it is no longer possible to continue, how can I dump everything
and come out of everything waiting for the user to press the button again
to do the process again?
The simple approach is you can do an Exit Sub at any point in a method to
return to the method that called it. You might want to set a global variable
like WasError to true and have each proceeding method check the flag to know
to just exit the previous method (not do anything) until the code returns
to the top call which should be the initial call from the button method. The
WasError is reset to false and the user can push the button again.

Jun 27 '08 #2
On Thu, 5 Jun 2008 03:07:55 +0100, "John" <in**@nospam.infovis.co.uk>
wrote:
>Hi

I have a button which calls a method which in turn calls another method,
which in turn calls another method. Let's say in the third method an error
occurs and it is no longer possible to continue, how can I dump everything
and come out of everything waiting for the user to press the button again to
do the process again?

Thanks

Regards
Put a Try/Catch around the top level call, and throw an error in the
third method. You can Catch all errors or only certain ones.
Jun 27 '08 #3
John wrote:
I have a button which calls a method which in turn calls another method,
which in turn calls another method. Let's say in the third method an error
occurs and it is no longer possible to continue, how can I dump everything
and come out of everything waiting for the user to press the button again to
do the process again?
Have a read about "Structured Exception Handling" and "Try .. Catch"

Sub Button1_Click( ... ) Handles Button1.Click
Try

Sub1()

Catch ex as Exception
' This catches [just about] ANY error
' You /can/ be more selective and pick a specific Exception
' if you can do something /useful/ with it

' Looking at the Exception class:
' ex.Message - /what/ went wrong,
' ex.StackTrace - /where/ it happened,
' ex.ToString() - gets the whole lot in one go.
' If you /log/ the error for later, log /this/.

MsgBox( "Oh Dear" & vbCrLf & ex.Message )

RecordToLogFile( ex.ToString() )

End Try
End Sub

Sub Sub1()
Sub2
End Sub

Sub Sub2()
Sub3
End Sub

Sub Sub3()
' Something that goes wrong
End Sub

HTH,
Phill W.
Jun 27 '08 #4
That is very close to the question I asked when someone started telling
me how wonderful all this structured stuff is vs. assembler where
everything is everything and you can do what you want. Data is data and
is only a character if you ask it to be and is a number if you ask it to
be without any change in the actual data or its location. If you
reference it with a math operator, it is a number, if you printing it on
paper, it is a character.

The actual answer is that you have to set all the traps and every
routine has to know what is going on with all that it has called and it
is a mess sometimes! Someone down deep gets an error and has to back
out all these levels and you have to code and be ready for it all the
way down so you can come all the way back and sit ready for the user
again.

People seem to think that all this plumbing is the greatest thing but I
will stop liking branch statements when the hardware stops using them!

And the folks who think that "On Error Resume Next" is useless needs to
read a few books by experts. The new Try/Catch business does NOT do
everything that needs be done. Resume Next is still necessary at times.
If I delete a file and it is not there, who cares? I just resume next
around it and I never know if it was there or not. I want it gone, when
I get through it is gone, mission accomplished. Yes, there can be some
other errors but those can be caught in one testing pass and then all is
done.

Mike

On Thu, 5 Jun 2008 03:07:55 +0100, in
microsoft.public.dotnet.languages.vb "John" <in**@nospam.infovis.co.uk>
wrote:
>Hi

I have a button which calls a method which in turn calls another method,
which in turn calls another method. Let's say in the third method an error
occurs and it is no longer possible to continue, how can I dump everything
and come out of everything waiting for the user to press the button again to
do the process again?

Thanks

Regards
Jun 27 '08 #5
I vaguely recall C (or at least Turbo C) had a mechanism to jump right back
to a previous location. Not that it matters so much what was in C anyway.

<Ju********@home.netwrote in message
news:mq********************************@4ax.com...
That is very close to the question I asked when someone started telling
me how wonderful all this structured stuff is vs. assembler where
everything is everything and you can do what you want. Data is data and
is only a character if you ask it to be and is a number if you ask it to
be without any change in the actual data or its location. If you
reference it with a math operator, it is a number, if you printing it on
paper, it is a character.

The actual answer is that you have to set all the traps and every
routine has to know what is going on with all that it has called and it
is a mess sometimes! Someone down deep gets an error and has to back
out all these levels and you have to code and be ready for it all the
way down so you can come all the way back and sit ready for the user
again.

People seem to think that all this plumbing is the greatest thing but I
will stop liking branch statements when the hardware stops using them!

And the folks who think that "On Error Resume Next" is useless needs to
read a few books by experts. The new Try/Catch business does NOT do
everything that needs be done. Resume Next is still necessary at times.
If I delete a file and it is not there, who cares? I just resume next
around it and I never know if it was there or not. I want it gone, when
I get through it is gone, mission accomplished. Yes, there can be some
other errors but those can be caught in one testing pass and then all is
done.

Mike

On Thu, 5 Jun 2008 03:07:55 +0100, in
microsoft.public.dotnet.languages.vb "John" <in**@nospam.infovis.co.uk>
wrote:
>>Hi

I have a button which calls a method which in turn calls another method,
which in turn calls another method. Let's say in the third method an error
occurs and it is no longer possible to continue, how can I dump everything
and come out of everything waiting for the user to press the button again
to
do the process again?

Thanks

Regards

Jun 27 '08 #6
VB has one too. It is named GoTo. It is a branch statement (one of the
VB curse words). It can go right back to the top of a nested bunch of
(almost) spaghetti code.

But is the ugly step-sister that is kept locked up in the basement that
no one ever talks about because it "can" enable "spaghetti code" to be
written.

And, OH MY, WE DON'T WANT SPAGHETTI CODE NOW, DO WE?????

Too bad some people never drove a manual shift and don't know to NOT use
their left foot on the brake pedal.

Too bad most programmers never wrote assembler - the code of champions -
and don't know how to avoid spaghetti code in the first place!

We have to save these poor souls from themselves!!!
BE SAVED!!!!!!!!!!!!

People can write spaghetti code in a structured environment, too.

It may be more difficult but still possible and still done, I expect.
Some of the stuff I have seen might as well be classified that way since
it is almost unreadable and unfollowable.

I only use "Goto" on an "On Error" statement but it can be used all by
itself. But don't do it or you will get a spanking and will be sent to
bed without any supper! Never mind it is completely legal to do...

Mike

On Mon, 23 Jun 2008 22:02:44 +0100, in
microsoft.public.dotnet.languages.vb "John" <in**@nospam.infovis.co.uk>
wrote:
>I vaguely recall C (or at least Turbo C) had a mechanism to jump right back
to a previous location. Not that it matters so much what was in C anyway.

<Ju********@home.netwrote in message
news:mq********************************@4ax.com.. .
>That is very close to the question I asked when someone started telling
me how wonderful all this structured stuff is vs. assembler where
everything is everything and you can do what you want. Data is data and
is only a character if you ask it to be and is a number if you ask it to
be without any change in the actual data or its location. If you
reference it with a math operator, it is a number, if you printing it on
paper, it is a character.

The actual answer is that you have to set all the traps and every
routine has to know what is going on with all that it has called and it
is a mess sometimes! Someone down deep gets an error and has to back
out all these levels and you have to code and be ready for it all the
way down so you can come all the way back and sit ready for the user
again.

People seem to think that all this plumbing is the greatest thing but I
will stop liking branch statements when the hardware stops using them!

And the folks who think that "On Error Resume Next" is useless needs to
read a few books by experts. The new Try/Catch business does NOT do
everything that needs be done. Resume Next is still necessary at times.
If I delete a file and it is not there, who cares? I just resume next
around it and I never know if it was there or not. I want it gone, when
I get through it is gone, mission accomplished. Yes, there can be some
other errors but those can be caught in one testing pass and then all is
done.

Mike

On Thu, 5 Jun 2008 03:07:55 +0100, in
microsoft.public.dotnet.languages.vb "John" <in**@nospam.infovis.co.uk>
wrote:
>>>Hi

I have a button which calls a method which in turn calls another method,
which in turn calls another method. Let's say in the third method an error
occurs and it is no longer possible to continue, how can I dump everything
and come out of everything waiting for the user to press the button again
to
do the process again?

Thanks

Regards
Jun 27 '08 #7

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

Similar topics

11
by: MLH | last post by:
I don't know how it happened. I have hundreds of hours worth of work invested in a file I foolishly named DB9.mdb. I was intending on renaming the file soon. But I neglected to do so before...
5
by: ruben20 | last post by:
Hi: Is there any way to recover data from a corrupted table? I can only run SELECTs on certain WHERE conditions. I cannot vacuum, pg_dump, I've deleted the indexes and try to reindex, always...
3
by: Sheldon | last post by:
Someone here at work was out and her backup, apparently, erased a very important table. While the Help Desk is trying to locate a backup tape, I was wondering if there is a way to get the table...
10
by: Philip Pemberton | last post by:
Hi, I'm currently playing around with a little spam filter for my Linksys NSLU2 (I would have used Spamassassin but that's slow even on my 2GHz Athlon64 - on a 266MHz XScale it's likely to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.