10-17-2014 09:31 AM
Hello everyone, I have a couple questions about Error Handling within a VI. I am using the Error In and Error Out clusters in my VI.
1. If a LabVIEW function node fails will it automatically skp any other code after that and just send all the error data to the error out cluster?
2. I have a VI in which if there is an error I want the VI to run a block of code before exiting. I'm worried that if I receive an error that it will skip the block of code before exiting. How do I make sure this block of code still gets executed?
Thanks for everyones help!
10-17-2014 09:39 AM
There is nothing special about an error. Well there sorta is but for this discussion the error is just a cluster of three elements. A String, a Boolean, and a Number.
If you pass in an error to your VI it does nothing different from if you were passing in any other data. But what you can do is have your code behave differently if an error is passed in. Lets say after some init you get an error, then you pass that error into your read. You wouldn't want your read to do anything because the init failed. So you would wire the error in to a case structure (right to the selector) and then if error, skip code, if no error do normal stuff.
You can use this how ever you like. So if you have a close function you will probably still want to try to close, but to maintain the error. So a close can ignore the error coming in and still operate, but then pass the error out which was passed in.
You can also write the code the way you asked, where if an error happened still do some stuff, but then have a case structure doing more stuff if an error occured or if it didn't.
You can get more specific too by unbundling the Code from the error, and performing different tasks if the error is a specific error.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
10-17-2014 10:06 AM
As was said, it all depends on how you code up your error handling.
If there is something I want to run regardless of an error, I typically clear the error and then procede with my code as normal. But then after that section, I use Merge Error with the "old" error and the error coming out of my little section. This way, I can still maintain that error and report it to whoever should see it.
10-21-2014 03:12 PM
Thanks for your help guys. With Automatic Error Handling enabled any code after it would not be run. For SubVIs, I always pass in an error case structure as you guys suggest. If there is an error that run that code if there is not an error then run this code. Here's my question: If the subVI has an error passed in and the error case then becomes true if I feed the error cluster wire into anything in this case it still will not run, correct? I need to make sure the wire is just fed through the case and nothing and no code in the error true case should be connected to the error cluster wire?
Thanks!
10-21-2014 03:21 PM
Correct. A small number of functions will execute regardless of error. Things like file close or refnum close. Check the help for the function to see for sure. Ones that don't execute with an incoming error should say something like they have Standard Error Functionality.
So if you want to be sure something runs despite an error, don't feed the error wire into those functions.
10-21-2014 04:58 PM
@RavensFan wrote:
Correct. A small number of functions will execute regardless of error. Things like file close or refnum close. Check the help for the function to see for sure. Ones that don't execute with an incoming error should say something like they have Standard Error Functionality.
So if you want to be sure something runs despite an error, don't feed the error wire into those functions.
Just to be ultra-safe, I merge the error out from the the code that isn't hooked up to the main error path to the main error path - with the main error path taking the top priority.