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).

1  
static Throwable pcall(Runnable r) {
2  
  try {
3  
    r.run();
4  
    return null;
5  
  } catch (Throwable e) {
6  
    return e;
7  
  }
8  
}
9  
10  
static O pcall(O o, S method, O... args) null on exception {
11  
  ret call(o, method, args);
12  
}
13  
14  
static <A> A pcall(IF0<A> f) null on exception {
15  
  ret f == null ? null : f!;
16  
}

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: 650 / 1169
Version history: 2 change(s)
Referenced in: [show references]