Compiler warning level in VB?

T

Thomas Jespersen

Hello

While trying to learn C# I discovered that the C# compiler has nice compiler
warnings like:

Unreachable code detected
Not all code paths return a value
A previous catch clause already catches all exceptions of this or a super
type ('System.Exception')

Is it possible to get these warnings in VB.NET too?

Thomas
 
H

Herfried K. Wagner [MVP]

Thomas,

* "Thomas Jespersen said:
While trying to learn C# I discovered that the C# compiler has nice compiler
warnings like:

Unreachable code detected
Not all code paths return a value
A previous catch clause already catches all exceptions of this or a super
type ('System.Exception')

Not available for VB.NET. You can only specify "/nowarn" or
"/warnaserror".
 
J

Jay B. Harlow [MVP - Outlook]

Thomas,
As Herfried stated, the VB.NET compiler itself does not support those
warnings.

I find these kinds of warnings are easily handled by a Code Critic or Code
Analyzer.

A Code Critic is a utility that looks at your code and gives you feedback on
what you should change to improve it.

Such as
http://www.fmsinc.com/reviews/tnanalyzer/sd1202.htm

Note: I have not use the above code analyzer to find your specific warnings,
it is simply an example of a Code Critic/Code Analyzer.

Hope this helps
Jay
 
A

Armin Zingler

Daniel said:
This is not a reply for thomas....

I would like to know if there's a reason why the VB.NET Compiler does
not check this:

1-
public function myFunction() as Integer
dim a as String
a="Hello"
end function

I think that the compiler can make a warning like: " Myfunction
should return " or " MyFunction does not return "

The compiler also can check if all path returns, for example:
function asd as integer
.......
.........
.........
if a>12 then
return 5
end if
end function

In this case if a <=12 , the function does not return...

Unless you have an infinte loop, a function always returns.

The function always returns the default value if you don't explicitly change
it.
2-

I think also the compiler could check if all the variables are
Initialized Ex:
sub main
dim a as Integer
dim b as Persona
if a = 3 then
........
end if
end sub

What does "initialized" mean? Every variable is automatically initialized.
It's not like C where you have garbage in it if you don't do it manually.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
H

Herfried K. Wagner [MVP]

* =?Utf-8?B?RGFuaWVs?= said:
I would like to know if there's a reason why the VB.NET Compiler does not check this:

1-
public function myFunction() as Integer
dim a as String
a="Hello"
end function

I think that the compiler can make a warning like: " Myfunction should return " or " MyFunction does not return "

I "guess" that there will be a warning in VB 2005, that not all code
paths in the function explicitly return a value, like in C#. Notice
that VB.NET initializes values so the return value will be 0 in this
case.
I think also the compiler could check if all the variables are Initialized
Ex:
sub main
dim a as Integer
dim b as Persona
if a = 3 then
........
end if
end sub

Why? VB.NET automatically initializes all variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top