LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

handling .net exceptions in LabVIEW

Hi,
 
I have a .net dll that is being called from LabVIEW 7.1. The dll, among other things, handles access to a database which may or may not be online when the user tries to access it so I have my dll throw a custom exception when the database is unavailable. The problem is that all exceptions from the dll are TargetInvocationExceptions with my custom exception as the inner exceptions. Is there a way to take the error out from a .net invoke or property node and get to the inner exception of the top level TargetInvocationException so that I can see (in LabVIEW) that it is a non-fatal exception (eg. is there a way to see the class of the exception?). Then I can just display a message in LabVIEW, something along the lines of "database unavailable, try again later". Of course, I still need to see potentially fatal exception that might be thrown because of bugs in my dll.
Any help on this would be greatly appreciated otherwise I have to come up with a completely different way of handling errors from my dll.
 
Thanks,
 
wjousts
 
 
0 Kudos
Message 1 of 4
(3,755 Views)
In 7.1, there isn't any information available to you on the exception - you get the standard 1172 error. In LV 8, more information is added to the error string (the message from the exception), but that isn't easy (or reliable) to parse for programatic control.
 
My suggestion would be to either put a try/catch around your DLL methods, and return the exception object from the method call (or null if no exception occurred). Or, if you know that the access to your DLL (or the instance of the object) is single threaded, then you could have the Last Error sort of property on the object, which you can query if you get an error in the error cluster.
 
Either way, once you get the refnum to the exception object, you can do all sorts of programatic handling, since it is really just a .NET object and so you have full access to the properties and methods (and type information) - including getting the inner exception.
Message 2 of 4
(3,752 Views)

Thanks for your suggestions. I'm thinking that probably a "last error" property will end up being the way to go. It might be a little tricky though as I have a couple of different objects.

As a suggestion for future version of LabVIEW though it would be pretty handy if the .net constructor, invoke and property nodes all had an exception out as well as the LabVIEW error out.

0 Kudos
Message 3 of 4
(3,743 Views)
Hi,

I am in a similar situation where I get an 1172 error but cannot find/locate the try/catch structure.  How does one creates a try/catch.  I found the exception class from my instrument's library.  I am using LV 8.2.
Searching the LV help has not been fruitfull.

Thanks in advance
Daniel

0 Kudos
Message 4 of 4
(3,571 Views)