From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Handling .NET Errors

I want to implement a .NET server (in C#) that will be used by LabVIEW.  LabVIEW has property nodes and invoke nodes that can access the properties and methods of my class.  What is the mechanism by which I return error information to LabVIEW, such that it appears at the "error out" of an invoke node or property node?  If I throw an exception, will LabVIEW catch it an handle it?
0 Kudos
Message 1 of 3
(2,596 Views)

Handling errors is easy and hard, depending on how much information you want at runtime. Any exception thrown in a call to a property or method is converted into a LV error w/ error code 1172. The information on the exception is then put into the error text, which is okay for humans to read, but I don't recommend writing code to try to parse it (at a minimum, we don't say that the format may not change in the future). Unfortunately, there isn't a way to get the exception object currently.

Therefore, you might want to think about saving off the exception object yourself (wrap your methods w/ a try/catch and a rethrow in the catch) in the object instance and expose it as a property. Thus you can access it via code at runtime for error handling cases. This, of course, assumes the server is either single threaded, or you'll use TLS (thread local storage) to store off the exception for the last method invoked.

Anyway, those are some initial thoughts on the matter. Feel free to reply w/ comments or questions.

0 Kudos
Message 2 of 3
(2,573 Views)

Hello,

I look at this thread which is from 2006. It says that there is no way to get information about .NET exception, except that parsing the text error.

Nowadays, Is there a way to get information about a .NET exception, for exemple a code, the name of  the exception ...

I use an assemby and I can't modify the code of this assemby

 

Thanks

Laurent

0 Kudos
Message 3 of 3
(2,198 Views)