How do I check if the Compile() method in Windev checks the code? - windev

The Compile() method returns an error when Windev can not compile it.
For instance (correct code):
teller is int = hnbrec("client")
result teller
This code returns the amount of items in de Client datafile.
But when I make a typo like:
teller is int = hnbrec("client")
result telles //should be teller
Windev does not mention an error...
But when I make a typo like:
teller iss int = hnbrec("client") //should be is
result teller
It throws a syntax error telling me it does not recognize iss.
How do I check the second example so it will throw an error?
EDIT:
However when I execute the code with
ExecuteProcess("<the process name>", trtProcedure)
The process will return an error saying it does not know telles...
But I don't want to execute the process, I only need to check it and write it to the database.

The compile function will only return errors if they are fatal enough:
"result telles" is not an error, as windev can't guess if it will exist at the time of execution; "telles" could be the name of a global variable or some other external ressource that isn't known by the compiler at this point since the context of the compilation here is that you are already in a running app that was precompiled and it does have access to the source code and cannot scan it to validate syntax anymore.
It will know that there is an error only when the interpretor executes the line (Yes it's more an "instanciated" code than a truly "compiled" code in traditionnal term that the name of the function Compile() would make believe...).
It just can't know that "telles" is wrong in such a dynamic context unless PCSFOT breaks the compile() function and forces a limited scope of just himself :)
I think in your case this will require a more defensive coding style:
WHEN EXCEPTION IN
teller is int = hnbrec("client")
result teller
DO
result -1 //Meaning something whent wrong in your function
END
And then when you call your dynamic proc you will have to test the returned value.
I hope this helps,
happy holidays!

Related

An unhandled exception of type 'System.StackOverflowException' occurred in VimService55.XmlSerializers.dll

I am working on an asp.net mvc-5 web application and i am using ap.net version 4.5.
Inside my web application I am executing some power-shell scripts to get some hardware info about some servers and VMs, and get back the results inside my code, as follows:
var shell = PowerShell.Create();
string PsCmd =
"add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '"
+ vCenterName.Trim() + "';$vCenterAdmin = '" + vCenterUsername.Trim()
+ "' ;$vCenterPassword = '" + vCenterPassword + "';"
+ System.Environment.NewLine;
PsCmd += "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;
PsCmd += "Get-VMHost " + System.Environment.NewLine;
shell.Commands.AddScript(PsCmd);
dynamic results = shell.Invoke();
var temp_result = results[0].BaseObject == null ? results[0] : results[0].BaseObject;
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
now currently when i run this inside my Visual Studio 2012 professional , i will get the following exception :-
System.StackOverflowException was unhandled
An unhandled exception of type 'System.StackOverflowException' occurred in VimService55.XmlSerializers.dll
on
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
So can anyone adivce on this? I know that in general a "StackOverflowException" exception is related to the fact that too many data exists inside the stack, but in my case I do not have control over this data as I am scanning VM server information. So can anyone advice on this please?
EDIT
I am not sure what is really raising the error (the debugger OR the code)? because when i try calling this code on the hosted application inside IIS (not inside Visual Studio) I will get null value for the otherIdentityInfo variable, rather than getting an exception. However, when i debug the code inside Visual Studio using Autos i will get the exception, so as #JmaesP mentioned the exception is being raised by the debugger, but not sure how i can debug this value to see why i am getting null??
A stack overflow exception from an XML serializer might indicate an issue with one of you serializable types. If the type declaration by itself is somewhat recursice, the default XML serializer will end up in inifite recursion. Consider this example:
[Serializable()]
public class Foo : IEnumerable<Foo>
{
public Foo()
{
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public IEnumerator<Foo> GetEnumerator()
{
throw new NotImplementedException();
}
public void Add(Foo item)
{
throw new NotImplementedException();
}
}
The default XML serializer first tries to figure out how to (de-)serialize an instance of Foo, then it tries to figure out how to (de-)serialize an IEnumerable<Foo>, and to do that it tries to figure out how to (de-)serialize a Foo — resulting in infinite recursion. Typically, a solution to this would to use a custom serializer as described here.
However, in your case the serializer is provided by the third-party component. The exception likely occurs during the serialization/deserialization that is happening when objects are passed from the PowerShell session to your process. So what you could to is to change the object that is returned from the PowerShell script. Instead of returning a VMHost object (requiring to serialize the entire object tree of the VMHost object), you could just return the SystemInfo or OtherIdentifyingInfo.
Large recursions can cause out-of-stack errors.
Your problem is likely that your program is attempting to consume an infinite amount /very large amount of stack.
Without seeing your stack trace, it's a bit difficult to provide a definitive answer, but I think sticking to the basics leads me to believe the source of your StackOverflow is the PsCmd += which continuously adding the data into the stack and results in StackOverflowException.
You can increase the stack size by using the below code:
Editbin.exe /Stack:14000000 "$(TargetDir)MyProject.exe"
Have you analyzed your code to find out that how deep your recursion goes on average? Does it always hit a StackOverflow? Try hardcoding a single entity and see the result.
Since 64 bit code can up more stack space than equivalent 32 bit code, large recursions can cause out-of-stack errors to occur earlier.
In that case, making the stack larger is not a good idea either. Instead we should find the deeply recursive algorithm and make it into an iterative one.
For Stack-Trace;
You can read up this property: Environment.StackTrace.
If the stacktrace exceded a specific threshold that you preset, you can return the function.
Note: From .Net 2.0 and above, you cannot get a StackOverflowException object using a try-catch block.
Let me know if at all it helps you.

Got exception in MR_workingName method when using com.apple.CoreData.ConcurrencyDebug 1

I create Core Data stack like this using MagicalRecord
MagicalRecord.setLoggingLevel(MagicalRecordLoggingLevel.Warn)
MagicalRecord.setDefaultModelNamed("myAPP.momd")
MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreNamed("myAPP")
then I add separated context to our persistent store for faster large imports
importContext = NSManagedObjectContext.MR_contextWithStoreCoordinator(NSPersistentStoreCoordinator.MR_defaultStoreCoordinator())
And all is working fine until I change MagicalRecordLoggingLevel.Warn to MagicalRecordLoggingLevel.Verbose
In this case I start getting exception in Magical Record method MR_workingName while com.apple.CoreData.ConcurrencyDebug 1 is set. So this method calls the exception
CoreData`+[NSManagedObjectContext __Multithreading_Violation_AllThatIsLeftToUsIsHonor__]:
in this string:
NSString *workingName = [[self userInfo] objectForKey:MagicalRecordContextWorkingName];
I never call MR_workingName method by myself from any thread.
Is this behavior OK? Or may be my stack is the reason I got this error.
Thank you!

SEGFAULT when passing QString by refernce to library function

I've been fighting with this all day long and I've tried passing a QString, a std::string, and a char* in many many different fashions, but if I pass it so that I can modify the parameter's value inside the library function then it SEGFAULTs. If I copy the library function, line for line, into the main app, I can pass references all day long as params and change their values inside the functions.
Here is the stripped down version of my function inside the library.
I have literally removed all code except for this line.
MySQLLib::ExecuteQuery(const QString& query, QString& results)
{
results = "Changed the value of this parameter.";
}
Here is the calling code from the main application.
bmdbTest is an instance of the above MySQLLib class...
All the other code in my library and application works. It just won't let me pass references to ANYTHING to my library.
MySQLProj::pbExecuteQuery_Click()
{
QString x = "Hello.";
bmdbTest->ExecuteQuery("SELECT ttid from test_table", x);
ui_MySQLProj1.textEdit->setText(x);
}
It SEGFAULTs on the bmdbTest->ExecuteQuery call.
I've even tried a simple int& as a parameter with no success.
I can however pass params as const QString& without issue. I just can't modify the param's value that way.
EDIT: I just figured it out. Thank you to "paxdiablo" for suggesting I check my variables for null or invalid pointers. I was really tired last night and I can't believe I missed this.
I just found the problem and I feel like a complete idiot. You mentioned about bmdbTest being null or invalid. The value of bmdbTest was fine as all my other functions worked fine, but when I was calling ExecuteQuery() I was passing the query string from the value in a QLineEdit from my GUI window like this.
bmdbTest->ExecuteQuery(leQuery->text(), resultString);
The leQuery->Text() was actually the problem as I must access leQuery like this.
bmdbTest->ExecuteQuery(ui_MySQLProj1.leQuery->text(), resultString);
You may want to check the value of bmdbTest itself. It may be null or an invalid pointer.
That seems to be indicated by the fact it's faulting on that line. If there were something suspect about the parameters, I would expect it to fault within the ExecuteQuery function.
You should be able to find out exactly where the crash is by putting suitable debug statements (with flushing) on either side of the results = ... and bmdbTest->ExecuteQuery(...) lines (or use a debugger if you have one).

Any side-effects using SqlParameterCollection.Clear Method?

I have this specific situation where I need to execute a stored procedure 3 times before I declare it failed. Why 3 times because to check if a job that was started earlier finished. I am going to ask a separate question for deciding if there is a better approach. But for now here is what I am doing.
mysqlparametersArray
do{
reader = MyStaticExecuteReader(query,mysqlparametersArray)
Read()
if(field(1)==true){
return field(2);
}
else{
//wait 1 sec
}
}while(field(1)==false);
MyStaticExecuteReader(query,mysqlparametersArray)
{
//declare command
//loop through mysqlparametersArray and add it to command
//ExecuteReader
return reader
}
Now this occasionally gave me this error:
The SqlParameter is already contained by another
SqlParameterCollection.
After doing some search I got this workaround to Clear the parameters collection so I did this:
MyStaticExecuteReader(query,mysqlparametersArray)
{
//declare command
//loop through mysqlparametersArray and add it to command Parameters Collection
//ExecuteReader
command.Parameters.Clear()
return reader
}
Now I am not getting that error.
Question: Is there any side-effect using .Clear() method above?
Note: Above is a sample pseudo code. I actually execute reader and create parameters collection in a separate method in DAL class which is used by others too. So I am not sure if making a check if parameters collection is empty or not before adding any parameters is a good way to go.
I have not ran into any side effects when I have used this method.
Aside from overhead or possibly breaking other code that is shared, there is no issue with clearing parameters.

ASP.NET Error Object reference not set to an instance of an object

Object reference not set to an instance of an object
I am getting this error sometimes.
I have a page where I load questions and for some question system generate this error. Why do I get this error? Please help me.
It means that somewhere something dereferences a null reference. Crude example:
Foobar foo = null;
foo.DoSomething(); // this line will trigger a NullReferenceException
Here's what you can do:
compile in debug mode
run it until it crashes
examine the stack trace; it will tell you where the exception originates (unless you're doing stupid things like catching and rethrowing improperly). You may have to follow the chain of inner exceptions
if that doesn't provide sufficient information, step through your code with a debugger until right before the call that makes it crash. Examine any variables that might be null.
Once you have found the culprit, you need to find out why it is null and what to do about it. The solution can be one of:
fix incorrect program logic that causes something to be null that shouldn't be
check if something is null before dereferencing it
handle the exception at a point that makes sense, and translate it into something more meaningful (probably some sort of custom exception)
You got null reference and if it can't handle it will show that message.
It can caused by some case
The return value of a method is null
A local variable or member field is declared but not initialized
An object in a collection or array is null
An object is not created because of a condition
An object passed by reference to a method is set to null
I suggest you to track the null value using a debug mode
You get this error, whenever you are trying to make use of variable with Null value in it.

Resources