txt: ## adhoc.md
  class X::AdHoc
  
  Error with a custom message
  
  ```raku
  class X::AdHoc is Exception { }
  
  ```
  
  `X::AdHoc` is the type into which objects are wrapped if they are thrown as exceptions, but don't inherit from [`Exception`](/type/Exception).
  
  Its benefit over returning non-[`Exception`](/type/Exception) objects is that it gives access to all the methods from class [`Exception`](/type/Exception), like `backtrace` and `rethrow`.
  
  You can obtain the original object with the `payload` method.
  
  ```raku
  try {
      die [404, 'File not found']; # throw non-exception object
  }
  print "Got HTTP code ",
      $!.payload[0],          # 404
      " and backtrace ",
      $!.backtrace.Str;
  ```
  
  Note that young code will often be prototyped using `X::AdHoc` and then later be revised to use more specific subtypes of [`Exception`](/type/Exception). As such it is usually best not to explicitly rely on receiving an `X::AdHoc` – in many cases using the string returned by the `.message` method, which all [`Exception`](/type/Exception)s must have, is preferable. Please note that we need to explicitly call `.Str` to stringify the backtrace correctly.
  
  # [Methods](#class_X::AdHoc "go to top of document")[§](#Methods "direct link")
  
  ## [method payload](#class_X::AdHoc "go to top of document")[§](#method_payload "direct link")
  
  Returns the original object which was passed to `die`.
  
  ## [method Numeric](#class_X::AdHoc "go to top of document")[§](#method_Numeric "direct link")
  
  ```raku
  method Numeric()
  ```
  
  Converts the payload to [`Numeric`](/type/Numeric) and returns it
  
  ## [method from-slurpy](#class_X::AdHoc "go to top of document")[§](#method_from-slurpy "direct link")
  
  ```raku
  method from-slurpy (|cap)
  ```
  
  Creates a new exception from a capture and returns it. The capture will have the `SlurpySentry` role mixed in, so that the `.message` method behaves in a different when printing the message.
  
  ```raku
  try {
      X::AdHoc.from-slurpy( 3, False, "Not here" ).throw
  };
  print $!.payload.^name; # OUTPUT: «Capture+{X::AdHoc::SlurpySentry}»
  print $!.message;       # OUTPUT: «3FalseNot here»
  
  ```
  
  The `SlurpySentry` role joins the elements of the payload, instead of directly converting them to a string.
  