VB... volete sapere a che riga c'è stato un errore?

Share on:

Usate una feature dimenticata nel tempo... ma ancora presente!

While typing some code, I noticed that REM is still supported as a way to comment code. The only reason I can see why one would want to do this is to retain legacy code. There are some other really old features that haven't been documented since VB3, most notably the useful ERL() function. (It is back in the official documentation as well.) This means the following is valid VB.Net code:

10: REM This program doesn't do much
20: Try
30:    REM Throw an error
40:    Throw New DivideByZeroException
50: Catch ex As DivideByZeroException
60:    Console.WriteLine("Error occured in line: " & Erl())
70: End Try
80: Console.ReadLine()

The output is:

Error occured in line: 40

The great thing about this, is that the line number is retained in a release build. I don't recommend using this globally in your applications as there is a performance hit (along with application bloat) but it is useful in selected circumstances. Naturally using the trace methods would be a better option.

Fonte: VB.ReallyOld features still in VB.2005

Post originale