LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error Handling Question

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!

0 Kudos
Message 1 of 6
(2,869 Views)

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.

Message 2 of 6
(2,864 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 6
(2,849 Views)

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!

0 Kudos
Message 4 of 6
(2,782 Views)

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.

Message 5 of 6
(2,777 Views)

@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.

merging errors.png

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 6 of 6
(2,765 Views)