Quirrel4.41.0

types.Class.pcall

Method on every class
class.pcall(...): any

Same as call, except a failure does not invoke the VM's registered error callback.

examples/types/class/pcall-basic.nut
class Rect { w = 0 constructor(w) { this.w = w } }
let r = Rect.pcall(null, 9)
println("r.w =", r.w)
Output:
r.w = 9

Parameters

...anythe constructor's arguments, with the same required-but-ignored leading value as call (see its Notes) repeats

Return value

The new instance.

Errors

A constructor failure still raises a normal, catchable script error; see call's Notes for the leading-argument rule and this page's Notes for what "protected" does and does not mean here.

Notes

The p in pcall stands for "protected call", but in Quirrel that protection is aimed at the host embedding the VM, not at the calling script: a failed pcall still throws, and an uncaught throw still stops the script. Wrap the call in try/catch if the script itself needs to recover.

Example

examples/types/class/pcall.nut
class Bad {
  constructor() { throw "boom" }
}
try {
  Bad.pcall(null)
} catch (e) {
  println("Bad.pcall(null) throws:", e)
}
Output:
Bad.pcall(null) throws: boom

See also

callCreates a new instance of the class and runs its constructor, the same as writing ClassName(...). Exists so a class value obtained indirectly (through a variable, a table slot, or getclass()) can still be instantiated through a uniform .call(...) spelling shared with functions.
pacallSame as acall, except a failure does not invoke the VM's registered error callback.
pcallCalls the closure like call does, using env as its this and forwarding the rest of the arguments as its own parameters.
classclass index