Bitburner

Bitburner

View Stats:
Cthary Mar 6, 2022 @ 2:46pm
Nuke ignores try-catch
Heyho,
i currently try to auto nuke servers.
The Problem is this:
try {
ns.nuke(server)
ns.print("SERVER="+server+" NUKED")
} catch { }

I get a "Script crashed with runtime error" here, "nuke: Not enough ports opened to use NUKE.exe virus.".

How can that be ? i mean, the error is correct but should be catched and ignored.

I solved the problem by creating checks beforehand... but still... why didn't it got catched ?
Last edited by Cthary; Mar 6, 2022 @ 2:56pm
< >
Showing 1-1 of 1 comments
Ekis93 Mar 7, 2022 @ 12:59pm 
You need to define the catch error. This for instance will catch any error event.

/** @param {NS} ns **/
export async function main(ns)
{
try { ns.nuke(host); }
catch { ErrorEvent; }
}

To elaborate; an empty catch should work since it's checking for any and all errors, but I've also run into situations where I get a runtime error while using an empty catch.
Last edited by Ekis93; Mar 7, 2022 @ 1:17pm
< >
Showing 1-1 of 1 comments
Per page: 1530 50

Date Posted: Mar 6, 2022 @ 2:46pm
Posts: 1