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

12
LINES

< > BotCompany Repo | #1015931 // expectException - assert that a code fragment throws an exception of a certain kind

JavaX fragment (include)

static void expectException(Class exceptionType, Runnable r) {
  try {
    r.run();
  } catch e {
    e = unwrapTrivialExceptionWraps(e);
    if (!isInstance(exceptionType, e))
      fail("Wrong exception type, was expecting " + exceptionType, e);
    silentException(e);
    ret;
  }
  fail("No exception thrown!");
}

Author comment

Began life as a copy of #1005129

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: #1015931
Snippet name: expectException - assert that a code fragment throws an exception of a certain kind
Eternal ID of this version: #1015931/2
Text MD5: 3cd37c4db7895b387cff65055844ca53
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-31 01:30:29
Source code size: 329 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 285 / 313
Version history: 1 change(s)
Referenced in: [show references]