Trap Error Condition

(imported topic written by MBARTOSH)

Is there a way to trap an error condition in relevance? For example, I am trying to determine whether or not WMI is broken. Using the following statement produces and error.

“not exists string values of selects “Domain from Win32_ComputerSystem” of wmi”

I would like to say something like “On Error” true.

(imported comment written by jeremylam)

The pipe (|) operator handles errors, but it works in quite a rigid manner. In this example I’ve misspelled the WMI query:

q: string value of selects “Domain from Win32_ComputerSysstem” of wmi | “error!”

A: error!

T: 3.686 ms

I: singular string

The right-side operand must be the same type (usually a string) and the same plurality (singular or plural) of the left hand operand.

// left side is plural, error

q: string values of selects “Domain from Win32_ComputerSysstem” of wmi | “error!”

E: A singular expression is required.

// left side is a boolean, error

q: exists string values of selects “Domain from Win32_ComputerSysstem” of wmi| “error!”

E: Incompatible types.

// cast left side as a string, works

q: (exists string values of selects “Domain from Win32_ComputerSysstem” of wmi) as string| “error!”

A: error!

T: 2.460 ms

I: singular string

If you can make your relevance query use an if / then / else structure, it may simpler to understand (but may be longer).

Good luck!

(imported comment written by MBARTOSH)

I am using this relevance to find all machines with broken WMI. “not exists wmi | true” . It works!

I am not completely sure how it works, but it does. Since wmi does not exist on systems with broken wmi the left side of the statement produces an error, but the vertical bar causes the error to be ignored or evaluated to false, and the answer ends up being the right side or true.