types.Class.pcall
Method on every
classSame as call, except a failure does not invoke the VM's registered error callback.
class Rect { w = 0 constructor(w) { this.w = w } }
let r = Rect.pcall(null, 9)
println("r.w =", r.w)Output:
r.w = 9Parameters
... | any | the 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
class Bad {
constructor() { throw "boom" }
}
try {
Bad.pcall(null)
} catch (e) {
println("Bad.pcall(null) throws:", e)
}Output:
Bad.pcall(null) throws: boomSee also
call | Creates 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. |
pacall | Same as acall, except a failure does not invoke the VM's registered error callback. |
pcall | Calls the closure like call does, using env as its this and forwarding the rest of the arguments as its own parameters. |
| class | class index |