ComputerCraft Archive

try catch

computer utility Poeschl github

Description

This is a utility class to add try - catch functionallity

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/Poeschl/computercraft-scripts/main/try-catch.lua try_catch
Archive:wget https://cc.shobie.xyz/cc/get/gh-Poeschl-computercraft-scripts-try-catch try_catch
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-Poeschl-computercraft-scripts-try-catch try catch

Usage

Run: try-catch

Tags

none

Source

View Original Source

Code Preview

-- This is a utility class to add try - catch functionallity
-- include it by downloading to your computer and import it with `require "try-catch"`

function catch(what)
  return what[1]
end

function try(what)
  local status, result = pcall(what[1])
  if not status then
     what[2](result)
  end
  return result
end