You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandException.Overwrite.md 904 B

123456789101112131415161718192021222324252627
  1. ---
  2. uid: Discord.Commands.CommandException
  3. ---
  4. ### Remarks
  5. This @System.Exception class is typically used when diagnosing
  6. an error thrown during the execution of a command. You will find the
  7. thrown exception passed into
  8. [LogMessage.Exception](xref:Discord.LogMessage.Exception), which is
  9. sent to your [CommandService.Log](xref:Discord.Commands.CommandService.Log)
  10. event handler.
  11. You may use this information to handle runtime exceptions after
  12. execution. Below is an example of how you may use this:
  13. ```cs
  14. public Task LogHandlerAsync(LogMessage logMessage)
  15. {
  16. // Note that this casting method requires C#7 and up.
  17. if (logMessage?.Exception is CommandException cmdEx)
  18. {
  19. Console.WriteLine($"{cmdEx.GetBaseException().GetType()} was thrown while executing {cmdEx.Command.Aliases.First()} in {cmdEx.Context.Channel} by {cmdEx.Context.User}.");
  20. }
  21. return Task.CompletedTask;
  22. }
  23. ```