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 977 B

12345678910111213141516171819202122232425262728293031
  1. ---
  2. uid: Discord.Commands.CommandException
  3. remarks: *content
  4. ---
  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. ---
  12. uid: Discord.Commands.CommandException
  13. example: [*content]
  14. ---
  15. You may use this information to handle runtime exceptions after
  16. execution. Below is an example of how you may use this:
  17. ```cs
  18. public Task LogHandlerAsync(LogMessage logMessage)
  19. {
  20. // Note that this casting method requires C#7 and up.
  21. if (logMessage?.Exception is CommandException cmdEx)
  22. {
  23. Console.WriteLine($"{cmdEx.GetBaseException().GetType()} was thrown while executing {cmdEx.Command.Aliases.First()} in {cmdEx.Context.Channel} by {cmdEx.Context.User}.");
  24. }
  25. return Task.CompletedTask;
  26. }
  27. ```