473,969 Members | 10,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 843

"John" <in**@nospam.in fovis.co.ukwrot e in message
news:e5******** ******@TK2MSFTN GP02.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.in fovis.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.publi c.dotnet.langua ges.vb "John" <in**@nospam.in fovis.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********@hom e.netwrote in message
news:mq******** *************** *********@4ax.c om...
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.publi c.dotnet.langua ges.vb "John" <in**@nospam.in fovis.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.publi c.dotnet.langua ges.vb "John" <in**@nospam.in fovis.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********@ho me.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.publ ic.dotnet.langu ages.vb "John" <in**@nospam.in fovis.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
2359
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 getting caught up in a new project. When I did, I forgot about the filename I was working under. One day, and I don't know how long ago it was, I deleted db*.mdb and db*.ldb from the development directory as a routine part of disk housekeeping.
5
4633
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 get error: ERROR: could not access status of transaction 4244329 DETAIL: could not open file "/usr/local/pgsql/data/pg_clog/0004": No
3
1697
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 back without having to find the backup of the database (if a backup tape can be found). Thanks, Sheldon Potolsky
10
3679
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 intolerably slow). As part of that, I'm keeping track of the DNSBL blocklists that are being queried using a dynamically-allocated array. When a new DNSBL zone is added to the zone array, I use realloc() to increase the amount of memory available...
0
10149
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11394
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10886
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10056
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7588
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6393
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5136
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 we have to send another system
3
3740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.