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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.NET-獲取在命令中引發(fā)哪種類型的異常

Discord.NET-獲取在命令中引發(fā)哪種類型的異常

C#
SMILET 2021-05-07 14:16:01
我認為,如果說一個人沒有運行命令的正確權限,或者有一個冷卻時間之類的東西,而不是僅僅每隔...一次就處理一次,則拋出異常會更容易。因此,我創(chuàng)建了自己的異常,但問題是CommandService.ExecuteAsync()。Error僅返回CommandError.Exception,無法(據我所知)無法發(fā)現拋出了哪種類型的異常。我的代碼如下:try { var result = await _service.ExecuteAsync(context, argPos);            if (!result.IsSuccess)                switch (result.Error)                {                    case CommandError.BadArgCount:                        await context.Channel.SendMessageAsync("Bad argument count.");                        break;                    case CommandError.UnknownCommand:                        break;                    case CommandError.Exception:                        // This is what happens instead of the catch block.                        break;                    default:                        await context.Channel.SendMessageAsync($"You ?? Broke ?? It ({result.ErrorReason})");                        break;                }        }        catch (Exceptions.GameCommandNotReadyException e)        {            // The code never gets here because of the CommandError.Exception        }
查看完整描述

1 回答

?
弒天下

TA貢獻1818條經驗 獲得超8個贊

您可能不想在此處使用try / catch,因為您不必要地拋出了自己的異常,然后在之后直接捕獲它。您可以將錯誤處理放入case CommandError.Exception。


如果您想更多地了解導致錯誤的異常,請執(zhí)行以下操作:


由于您正在調用該ExecuteAsync函數,因此“結果”可能不僅是類型IResult,而且是ExecuteResult類型。這意味著將存在一個屬性“ Exception”,該屬性存儲“出了什么問題”。


case CommandError.Exception:

    if (result is ExecuteResult execResult)

    {

        //you can now access execResult.Exception to see what happened

    }


break;


查看完整回答
反對 回復 2021-05-21
  • 1 回答
  • 0 關注
  • 201 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號