Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1001180 // pcall - safe calling (like in Lua)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2509L/16K).

static Throwable pcall(Runnable r) {
  try {
    r.run();
    return null;
  } catch (Throwable e) {
    return e;
  }
}

static O pcall(O o, S method, O... args) null on exception {
  ret call(o, method, args);
}

static <A> A pcall(IF0<A> f) null on exception {
  ret f == null ? null : f!;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001180
Snippet name: pcall - safe calling (like in Lua)
Eternal ID of this version: #1001180/3
Text MD5: b943be649462094264dbae9ed4c3794b
Transpilation MD5: 3221c880c6f65339a89bb9ea4b78aaaa
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-02 15:30:36
Source code size: 309 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 727 / 1275
Version history: 2 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1024852 - rcall_pcall - safe calling with reverse syntax
#1031602 - pcallWithEnter - safe calling (like in Lua)
#3000382 - Answer for ferdie (>> t = 1, f = 0)