views:

217

answers:

1

When writing code in JScript, as I am wont to do as I have never been a fan of ASP.Net and Jscript is infinitely more elegant than VBScript, you can call upon the arguments collection. This is extremely useful to pass into error handlers as you can then output messages to development teams which tell them exactly what the state of the app was at the time of the error, down to what was passed to the procedure which errored. Because it is intrinsic there is no need to mess about, just pass it as an argument to your central exception handler.

My question is this: Is there anything similar in .Net, specifically VB?We inherited a shonky application which we have been steadily improving (most of it had no error handling to speak of) but one thing that I find very annoying is not having the details of what was in function arguments in the error reports the app emails to the dev group and mroe foten than not this information is key to the error itself.

Cheers all

+2  A: 

There are two questions here. The first is how do you pass an arguments collection to a Sub in VB. The answer is you don't. VB is a strongly typed language and argument collections in JScript are not. However, you can accomplish the same effect using an Array as a parameter.

If you have a function like this:

Function Sum(ByVal ParamArray nums As Integer()) As Integer 
  Sum = 0  
  For Each i As Integer In nums 
    Sum += i 
  Next 
End Function

Then you can call it like this:

Dim total As Integer = Sum(4, 3, 2, 1)

Your second question is about setting up a good error handling system. Turns out, .Net has a sweet error handling architecture baked right in using exceptions. Check out this site for some good details on setting up an exception handling system.

Mark Ewer
Thanks Mark, I had no idea this had been replied to again. I was well aware of the .Net exception handling (and you're dead right - totally sweet!) but I've given up on the idea of the argument collection. It was always a long shot, but I figured I'd see if there was something buried deep in the framework I'd not seen before. Should have thought about it a little more first really. Thanks for taking the time to reply though, much appreciated.
Steve Pettifer