LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to throw custom error from SubVI

Hi

 

I was wondering how best to throw error messages from a SubVI.

 

Say I have a toplvl VI called Caller.vi which calls Sub.vi. The toplvl vi whishes to use the Sub.vi's error out cluster to determine what to do - e.g. halt execution of the toplvl vi if the Sub.vi throws an error. Easy enough if the Sub.vi just have to pass errors from build in LabView functions and VI's, but how to do it if the sub vi has to throw a custom error upon some condition?

 

Say the sub vi takes a certain number of inputs and that the inputs need validation before executing what ever the sub vi does. E.g. a certain algorithm implemented is only meaningfull if a>10.

 

My own thought is this: Simply select between an empty/no-error error cluster and an error-cluster containing the wanted custom errorcode and description. The area circled in blue is the interesting part:

 

block_diagram_throw_error.png

 

Is that the worst idea you've iever seen implemented?

 

The only other real suggestion I've been able to find (which originally adresses another issue, but shows a method for "throwing an error") is a VI posted in this thread: http://forums.ni.com/t5/LabVIEW/Throw-an-error/m-p/882575 which looks like:

 

block_diagram_from_other_post.png

 

Please help me out guys 🙂 How to throw a custom error which is not intended for the end-user, but intended to ease the life of a develper calling the sub-vi if he/she wishes to.

 

Best regards

Wuhtzu

0 Kudos
Message 1 of 9
(22,521 Views)

Forgive me for elaborating in a reply - I just fear that editing the orignal post to much could cause trouble.

 

 

And what about "tools-> advanced -> edit error codes." If I can just "throw" errors by constructing an errorcluster and wire it to / merge it with the normal error cluster why should I go about adding those custom errors? And if I add a custom error using "tools -> advanced -> edit error codes" the question about how to throw them still remans for me.

 

Best regards

Wuhtzu

0 Kudos
Message 2 of 9
(22,508 Views)

Forgive me again, this time for bumping the topic, if that's not accepted behavoir on this board.

 

But I find it strange that 0 out of 57 people know and/or have an opinon on how to throw errors from a SubVi... it should be one of the most common tasks to perform 🙂

0 Kudos
Message 3 of 9
(22,462 Views)

Please be patient.  We are all volunteers here, most of us have regular jobs and can't respond on the spur of the moment. 

 

I usually create my own error clusters such as what you demonstrated in the your top most picture.  You build your own error cluster and wire in True for Status, wire in your own error code (from 5000 to 9999 for user defned errors), and wire in a string that describes the error.  It is good practice to include the vi name in your error string so that you know which vi created the error.

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 9
(22,454 Views)

Here is an example of creating an error in my state machine example.  I didn't put the VI name in the error string because this is a template I use and the name changes every time I use it.

 

StringStateMachineWithEventsTemplate_BD.png

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 9
(22,447 Views)

I like "error cluster from error code.vi"  easy peasy.  You wire the code, it will supply the source/call chain, it no-ops on upstream errors, you can add additional info to "message".  You can use a built in code or make one up from the user-defined ranges.

-Barrett
CLD
Message 6 of 9
(22,441 Views)

Thank you tbob. (EDIT: and thank you blawson)

 

I know all about volunteering and having jobs to do - I participate in quite a few fora. I just thought that my topic was lost since after only 2 days it was on page 3 of the forum - but if page 3 isn't forgotten I will remember that next time and also if 2 days isn't patient I will also remember that 🙂

 

To you answer: The error code should be negative, shouldn't it? Even though an indicator wired to error-out of a build in labview function will actually display error codes as positive... maybe it's diffrent form labview version to labview version. My v2010 manual reads:

"You can define custom error codes in the range of -8999 through -8000, 5000 through 9999 or 500,000 through 599,999"

 

So say I want to throw an error with error code 5687 - should I then wire -5687 or +5687 to the cluster?

 

Thanks - Wuhtzu

 

 

0 Kudos
Message 7 of 9
(22,439 Views)

To me it really doesn't matter if the error code is positive or negative.  Personal preference.  As long as it is in the range that NI allows for user defined codes.  Some people prefer negative numbers.  If you are one of those, then use a negative number.  It doesn't affect the way Labview operates.  If the Status is True, then it is an error.  If Status is false and the code is non-zero, with the string being non-blank, then it is a warning.

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 9
(22,420 Views)

I know this is an ancient post, but it's ranked high in Google for Labview error handling queries.  I think I came up with a quick, readable solution to the OP's question, and wanted to share.  

Untitled.png

Basically you wire an error cluster and "error in" into a Select, switching off of the error conditional.  The error cluster has status set to true and the error code you want.  The trick for me was to route the cluster through a Bundle By Name first, so you can overwrite the "source" string with a custom error message.  Once you've trimmed the "status" and "code" elements off of the Bundle By Name, and selected "View as Icon" on the cluster, the end result is concise enough to copy and paste everywhere without needing a sub VI.

 

 

Message 9 of 9
(21,085 Views)