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

10
LINES

< > BotCompany Repo | #1000659 // fail functions (improved)

JavaX fragment (include)

static RuntimeException fail() { throw new RuntimeException("fail"); }
static RuntimeException fail(Throwable e) { throw asRuntimeException(e); }
static RuntimeException fail(O msg) { throw new RuntimeException(String.valueOf(msg)); }

ifndef fail_dontUseFailClass
static RuntimeException fail(O... objects) { throw Fail(objects); }
endifndef

static RuntimeException fail(S msg) { throw new RuntimeException(msg == null ? "" : msg); }
static RuntimeException fail(S msg, Throwable innerException) { throw new RuntimeException(msg, innerException); }

Author comment

This is smartly declared so you can use either version:

  fail();
  throw fail();

(Actually JavaX, as of #752, now rewrites "fail()" to "throw fail()".)


// disabled for now to shorten some programs 
/*static RuntimeException fail(S msg, O... args) {
  throw new RuntimeException(format(msg, args));
}*/

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000659
Snippet name: fail functions (improved)
Eternal ID of this version: #1000659/9
Text MD5: 2807eaf197b1e226e5c3d7b24e11fc52
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-09 19:50:04
Source code size: 561 bytes / 10 lines
Pitched / IR pitched: No / No
Views / Downloads: 1019 / 10581
Version history: 8 change(s)
Referenced in: #1000716 - confused functions
#1000905 - error functions
#1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1009495 - quickFail functions - throw RuntimeException without stack trace
#3000382 - Answer for ferdie (>> t = 1, f = 0)