nate0187
asked on
VB.NET: How to throw a compiler error?
Simple question. How do you force the VB compiler to throw a compilation error, like you do in C#?
Example in C#:
You can use a diagnostic directive:
or for just a warning:
Example in C#:
You can use a diagnostic directive:
#error Oops. This is an error.
or for just a warning:
#warning This is just a warning.
I don't know how it can be done in VB but I am curious about your requirement in having this?
ASKER
@emoreau Most of or staff are hard core C# users, a few people still VB. We have to convert code a lot of times for different projects. The #error or #warring doesn't convert from C# to VB, It would be nice to use the same code with out having to modify it.
I agree that it should convert. I was just asking in which scenario these directives are useful.
There is no equivalent. The closest equivalent I can think of is just to write something that won't compile. Like
Oops_this_is_an_error 'Should say something like "Oops_this_is_an_error is not defined"
If you don't use Option Explicit, you could do something like
err=Oops_this_is_an_error
Anyway, the idea is just to write something that will BE an error that has the information you want to communicate in it somewhere.
It's not as clean, but it gets the job done.
We always treat warnings as errors so we don't need the distinction, but you should be able to use the same idea for warnings as well.
Oops_this_is_an_error 'Should say something like "Oops_this_is_an_error is not defined"
If you don't use Option Explicit, you could do something like
err=Oops_this_is_an_error
Anyway, the idea is just to write something that will BE an error that has the information you want to communicate in it somewhere.
It's not as clean, but it gets the job done.
We always treat warnings as errors so we don't need the distinction, but you should be able to use the same idea for warnings as well.
ASKER
@TommySzalapski You are right that example is not clean at all. That is why I like the C# way of sending an error to the compiler freely, without having to throw an exception.
ASKER
@emoreau These directives are useful are very useful in debugging, and sending errors to the compiler in a programmatic way from the end user on the fly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The link was useful.