Hi,
Is it possible to 'fix'in the catch block whatever caused an exception and
return to the offending statement in the try block, and try it again?
After raising an exception, I'd like to try to resume the computation after
fixing whatever went wrong. 6 6328
I don't know all the details of the code you wrote or intend to write.
If you know which statement can cause the problem (throw the exception),
then you can enclose that statement in a separate try-catch block. The catch
block will handle the problem, then the execution will continue with the
next statement.
Catalin
"Boogie El Aceitoso" <fr****@telefonica.net> wrote in message
news:kl********************************@4ax.com... Hi,
Is it possible to 'fix'in the catch block whatever caused an exception and return to the offending statement in the try block, and try it again?
After raising an exception, I'd like to try to resume the computation
after fixing whatever went wrong.
On Wed, 12 Nov 2003 14:51:15 +0100, Boogie El Aceitoso
<fr****@telefonica.net> wrote: Hi,
Is it possible to 'fix'in the catch block whatever caused an exception and return to the offending statement in the try block, and try it again?
You can't.
The book "The Design and Evolution of C++" by Bjarne Stroustrup
explains why there isn't a way to do this (you can do something
slightly similar in some languages I think, VB for one, although I
can't imagine anyone wanting to copy VB's error handling model!).
After raising an exception, I'd like to try to resume the computation after fixing whatever went wrong.
It may be that exceptions aren't what you should be using here. Why
not handle the error where it happens, and then continue if you can?
Why are you letting the exception propogate out of the operation?
Tom
"Boogie El Aceitoso" <fr****@telefonica.net> wrote in message
news:kl********************************@4ax.com... Hi,
Is it possible to 'fix'in the catch block whatever caused an exception and return to the offending statement in the try block, and try it again?
After raising an exception, I'd like to try to resume the computation
after fixing whatever went wrong.
No. Basically, exceptions were designed for cases where you *can't* fix it
and continue - at least not on the same path. If you have such a case, then
supposedly you shouldn't throw an exception, but deal with it in some other
way. It's like a function is saying "it's not possible", and you're
replying "try harder". If he *could* try harder, he should have done so
before throwing an exception!
Boogie El Aceitoso wrote: Hi,
Is it possible to 'fix'in the catch block whatever caused an exception and return to the offending statement in the try block, and try it again?
After raising an exception, I'd like to try to resume the computation after fixing whatever went wrong.
No. C++ exceptions use the Ada model.
If you really want to do fix it, you could try this:
for (;;)
{
try
{
// YOUR EXCEPTION PRONE CODE HERE!!!!
break;
}
catch (some_exception_type& ex)
{
// fix something
}
catch (some_other_exception_type& ex)
{
// fix something
}
// etc...
}
This will keep trying until you either get something that works, or give up and throw an exception that you don't look for in your
catch blocks.
"red floyd" <no*****@here.dude> wrote in message
news:5B*****************@newssvr25.news.prodigy.co m... No. C++ exceptions use the Ada model.
If you really want to do fix it, you could try this:
for (;;) { try { // YOUR EXCEPTION PRONE CODE HERE!!!! break; } catch (some_exception_type& ex) { // fix something } catch (some_other_exception_type& ex) { // fix something } // etc... }
This will keep trying until you either get something that works, or give
up and throw an exception that you don't look for in your catch blocks.
If you are not very careful it will just repeat the same code over and over
again, trying the same fix each time. I think it is hard to see a good
general way to avoid that problem, so I prefer wrapping the repeated code in
a function, and re-calling that function in the catch blocks if the problem
looks fixable.
Kevin Saff wrote: "red floyd" <no*****@here.dude> wrote in message news:5B*****************@newssvr25.news.prodigy.co m...
No. C++ exceptions use the Ada model.
If you really want to do fix it, you could try this:
for (;;) { try { // YOUR EXCEPTION PRONE CODE HERE!!!! break; } catch (some_exception_type& ex) { // fix something } catch (some_other_exception_type& ex) { // fix something } // etc... }
This will keep trying until you either get something that works, or give
up and throw an exception that you don't look for in your
catch blocks.
If you are not very careful it will just repeat the same code over and over again, trying the same fix each time. I think it is hard to see a good general way to avoid that problem, so I prefer wrapping the repeated code in a function, and re-calling that function in the catch blocks if the problem looks fixable.
You're correct. I wasn't clear in my earlier post. That's what the "give up" comment was about.
Sooner or later, you need to say, "enough is enough", toss in your cards, and throw an exception that you deliberately don't catch. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Darta |
last post by:
OK- I volunteer to be shot if this question is stupid... BUT, is there
a way to, when you catch an exception in the catch{} handler, resume
to the same line of code that generated an error while...
|
by: Rob R. Ainscough |
last post by:
Coming from VB6 to VB.NET, it appears if I opt to use the Try Catch approach
I don't have any way to RESUME from within my catch statement?
What I often do is resolve the problem in my catch...
|
by: itsupport1 |
last post by:
Hi,
I am importing some records from one table to another table, and due to
Constraints in the destination table, it Throws an Exception and Skip the
Whole Rest of records.
So I did implement...
|
by: Neo |
last post by:
Hello All,
Although, I have read all the advantages of using Try Catch Block
instead of "On error goto", I am still confused what is alternative for
classic "Resume" statement. "Resume" was one...
|
by: fniles |
last post by:
In VB 6.0 in the error trapping, we can do "resume next" to continue on the
next code. How can we do that in .NET with "Try", "Catch","End Try" ?
Thanks
| |
by: Rob R. Ainscough |
last post by:
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...
|
by: Maxwell2006 |
last post by:
Hi,
I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?
Thanks,
|
by: kimiraikkonen |
last post by:
Hi,
I want to find out if there's difference between "On Error Resume
Next" error handler and leaving "catch" block empty in a try-catch-end
try block to ignore exceptions which i don't approve of...
|
by: sriharikabattula |
last post by:
hi,
i am uploading .doc,.docX,rtf files during registration level and that path can be saved in database(i am using database MYSQL).when user want to see his resume he/she can login and retrive...
|
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...
|
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...
| |
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,...
|
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: 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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |