473,387 Members | 1,463 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.

VB Resume statement equivalent in try-catch ....

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 you are
debugging within IDE...? Here is an example from VB:

Private SomeFunction ()
On Error GoTo ErrHandler:

MyMethod this, that

Exit Function
ErrHandler:
Err.Raise smth, smth, smth
Exit Function ' this is for safe-keeping, although not necessary
since
' Err.Raise exits the function anyways
Resume
End Function

In VB world, I would set a breakpoint on Err.Raise line, the execution
will stop when error happens on that line, then I would -manually-
drag a cursor to Resume, and then Step Into would bring me to the
exact line that cause the error in the function. This was very handy
and effective as I could immediatelly tell which call caused the error
and with next Step Into, what was the error while debugging. I can't
find a similar way in catch{} statement. You can view the message,
get Source and StackTrace, and all the other stuff from the various
Exception objects, but you have to read all those properties to see
where exactly the error occurred - which is so much slower than the
way I described. Or there might be a way to do this in C#, which I am
not aware of... (also, as you noticed, my VB approach is only for
debugging purposes, as Resume will never executed when running the
code real time as Err.Raise exits the function anyways...)

Any help is greatly appreciated.
Tigger
Nov 15 '05 #1
2 6743
Tigger:

When I first came to my shop, they didn't use Structured Exception handlers
at all b/c they used this same method and coudln't get line numbers of the
exception. They were using ex.Message and this didn't give them what they
needed.
Use a Try Catch block and then in your exception handler, Exception.ToString
will give you the exact line number and description of the error, coupled
with the stack trace.

This should get you what you want.

HTH,

Bill
"Darta" <tv****@hotmail.com> wrote in message
news:db**************************@posting.google.c om...
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 you are
debugging within IDE...? Here is an example from VB:

Private SomeFunction ()
On Error GoTo ErrHandler:

MyMethod this, that

Exit Function
ErrHandler:
Err.Raise smth, smth, smth
Exit Function ' this is for safe-keeping, although not necessary
since
' Err.Raise exits the function anyways
Resume
End Function

In VB world, I would set a breakpoint on Err.Raise line, the execution
will stop when error happens on that line, then I would -manually-
drag a cursor to Resume, and then Step Into would bring me to the
exact line that cause the error in the function. This was very handy
and effective as I could immediatelly tell which call caused the error
and with next Step Into, what was the error while debugging. I can't
find a similar way in catch{} statement. You can view the message,
get Source and StackTrace, and all the other stuff from the various
Exception objects, but you have to read all those properties to see
where exactly the error occurred - which is so much slower than the
way I described. Or there might be a way to do this in C#, which I am
not aware of... (also, as you noticed, my VB approach is only for
debugging purposes, as Resume will never executed when running the
code real time as Err.Raise exits the function anyways...)

Any help is greatly appreciated.
Tigger

Nov 15 '05 #2
Hi Darta,

"Darta" <tv****@hotmail.com> wrote in message
news:db**************************@posting.google.c om...
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 you are
debugging within IDE...? Here is an example from VB:

<snip>

There is no direct equivalent to Resume in C#.

You might find it interesting to see the difference in the generated
machine instructions when you use Resume v.s. when you don't. Obviously
there isn't a one-to-one relationship between code lines and generated
machine code instructions. So how does your VB program "know" which line it
should resume to? The answer is that an invisible line counter is maintained
in any routine that uses Resume or Resume Next. For every line of code an
extra instruction is generated to increment the line counter.

In other words, simply by including the Resume or Resume Next statement
in a routine will slow the routine down, even if the Resume or Resume Next
statement is never executed. I doubt the difference is significant in most
cases, but it's interesting anyway.

Regards,
Dan
Nov 15 '05 #3

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

Similar topics

6
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
3
by: Laphan | last post by:
Hi Everybody I put the On Error Resume Next command as the very first line in my ASP pages, which may contain various inc files and sub-routines/functions, so that I can try and stop the dreaded...
14
by: Jiri Kripac | last post by:
Languages such as Simula 67 contain a general concept of coroutines that allow the execution of a method to be suspended without rolling back the stack and then later resumed at the same place as...
0
by: kjr | last post by:
In VB6 I was able to trap and error and if I wanted to ignore the error (e.g. Invalid use of null or InvalidCastException: a db column was null when reading into a variable) I could "Resume Next"...
5
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...
2
by: juky | last post by:
Hi all, I have a loop in the thread checking for a particular service status, whenever the status changes to "stopped" a RaiseEvent is generated by thread and another function runs. At the same...
3
by: bob.needler | last post by:
I know On Error Resume Next is generally considered lazy. But can someone tell me why the resume next in Exit_Handler does not seem to work? It generates the typical unhandled runtime error...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
26
by: a.mil | last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff and I encountered the following problem: When I have a for loop like this: b=b0; for (a=0,i=0;i<100;i++,b--) { if (b%i)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
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...

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.