Home All Groups Group Topic Archive Search About

Current namespace, stack and lineno

Author
25 Aug 2006 3:29 AM
markroworth
Hi everyone,

I'm relatively new to vb.net and am writing my errors object to collect
errors as the call stack bounces back up to the GUI. When an error
occurs, I would like to grab three things:

1. the line no the error occurred on
2. the current namespace. e.g. MyApplication.MyClass.MyFunction
3. the callstack.

Does anyone know how to do this. Also, having transferred over recently
from VB6, is there any way to query as in the immediate window of VB6
at runtime. Or for that matter, change the code at runtime (in the dev
environment, obviously).

Any information very gratefully received. Many thanks,

Mark Roworth

Author
25 Aug 2006 3:52 AM
GhostInAK
Hello markroworth,

Check out the StackTrace and Exception classes.

-Boo

Show quoteHide quote
> Hi everyone,
>
> I'm relatively new to vb.net and am writing my errors object to
> collect errors as the call stack bounces back up to the GUI. When an
> error occurs, I would like to grab three things:
>
> 1. the line no the error occurred on
> 2. the current namespace. e.g. MyApplication.MyClass.MyFunction
> 3. the callstack.
> Does anyone know how to do this. Also, having transferred over
> recently from VB6, is there any way to query as in the immediate
> window of VB6 at runtime. Or for that matter, change the code at
> runtime (in the dev environment, obviously).
>
> Any information very gratefully received. Many thanks,
>
> Mark Roworth
>
Author
25 Aug 2006 10:46 AM
Phill W.
markroworth wrote:

> When an error occurs, I would like to grab three things:
>
> 1. the line no the error occurred on
> 2. the current namespace. e.g. MyApplication.MyClass.MyFunction
> 3. the callstack.

Try
    SomethingIffy()

Catch ex As System.Exception
    Console.Writeline( ex.ToString() )

End Try

The Exception class has lots of useful properties that you can use to
pull the error apart (StackTrace and Message being the most useful).

> is there any way to query as in the immediate window of VB6
> at runtime.

There's an Immediate Window in Visual Basic ('2002, '2003 and '2005 -
you didn't say which one you're using).

> Or for that matter, change the code at runtime

"Edit and Continue" is back in VB'2005 (for Console and Forms app's,
anyway) but there have been /many/ reports of [*very*] poor performance
when debugging with it switched on.
That /may/ [have] improve[d] with SP1 (is that out yet?); I can't
confirm/deny this.

HTH,
    Phill  W.
Author
26 Aug 2006 2:06 AM
markroworth
Thanks guys, that's solved my problems.

Phill W. wrote:
Show quoteHide quote
> markroworth wrote:
>
> > When an error occurs, I would like to grab three things:
> >
> > 1. the line no the error occurred on
> > 2. the current namespace. e.g. MyApplication.MyClass.MyFunction
> > 3. the callstack.
>
> Try
>     SomethingIffy()
>
> Catch ex As System.Exception
>     Console.Writeline( ex.ToString() )
>
> End Try
>
> The Exception class has lots of useful properties that you can use to
> pull the error apart (StackTrace and Message being the most useful).
>
> > is there any way to query as in the immediate window of VB6
> > at runtime.
>
> There's an Immediate Window in Visual Basic ('2002, '2003 and '2005 -
> you didn't say which one you're using).
>
> > Or for that matter, change the code at runtime
>
> "Edit and Continue" is back in VB'2005 (for Console and Forms app's,
> anyway) but there have been /many/ reports of [*very*] poor performance
> when debugging with it switched on.
> That /may/ [have] improve[d] with SP1 (is that out yet?); I can't
> confirm/deny this.
>
> HTH,
>     Phill  W.