第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何捕獲異常并且不停止代碼執(zhí)行

如何捕獲異常并且不停止代碼執(zhí)行

不負(fù)相思意 2022-11-02 17:01:12
我想捕獲 InputMissmatchException 但不停止重新執(zhí)行代碼(我希望 while 循環(huán)再次重新運(yùn)行,直到給出適當(dāng)?shù)妮斎耄┱麛?shù)選擇 = 0;布爾循環(huán)=真;    while(loop){        printInstruction();        choice = scanner.nextInt();        //catch InputMissmatchException        switch(choice){            case 0:                loop = false;                break;            case 1:                addCustomer(mohamad,sgbl);                break;            case 2:                deleteCustomer(sgbl);                break;            case 3:                seeInfo(sgbl);                break;            case 4:                makeTransaction(mohamad);                break;            case 5:                seeTransactionLog(mohamad);                break;            default:                System.out.println("try again");        }    }
查看完整描述

1 回答

?
郎朗坤

TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個(gè)贊

int a = -1;

while(true)

{

  try

  {

      Scanner in = new Scanner(System.in);

      a = in.nextInt();

  }

  catch(InputMismatchException e)

  {

      e.printStackTrace();   

  }


  //Your switch statement 

 }

順便說一下,a 的默認(rèn)值設(shè)置為 -1。如果發(fā)生異常,則進(jìn)入 switch case 時(shí)的值將是 -1。


int a = -1;

while(true)

{

  try

  {

      Scanner in = new Scanner(System.in);

      a = in.nextInt();

  }

  catch(InputMismatchException e)

  {

      e.printStackTrace();   

      continue;

  }


  //Your switch statement 

 }

如果您使用 continue 則循環(huán)的當(dāng)前迭代將停止并運(yùn)行下一次迭代


查看完整回答
反對(duì) 回復(fù) 2022-11-02
  • 1 回答
  • 0 關(guān)注
  • 102 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)