TheSwamp

Code Red => .NET => Topic started by: Grrr1337 on December 02, 2018, 03:55:07 PM

Title: Throwing Errors
Post by: Grrr1337 on December 02, 2018, 03:55:07 PM
Hey .NET guys!
When defining a method by using the LispFunction attribute, like so
Code - C#: [Select]
  1. [LispFunction("Test")]
  2. public static void Test(ResultBuffer rbArgs)
  3. {
  4.   ...
  5. }

Normally one would provide the arguments from LISP and then we'd iterate through the ResultBuffer to check if they are valid/as expected for the method.
But how to throw the errors like in these standard LISP functions ? :

Code - Auto/Visual Lisp: [Select]
  1. _$ (rtos "a")
  2. ; error: bad argument type: numberp: "a"
  3. _$ (strcat 0 1)
  4. ; error: bad argument type: stringp 0
  5. _$ (getint "Here" "I" "Provide" "Many" "Arguments")
  6. ; error: too many arguments

I'm looking for something like this guide (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/exceptions/creating-and-throwing-exceptions) but that would work for ACAD
Code - C#: [Select]
  1. throw new System.ArgumentException("Parameter cannot be null", "original");
Title: Re: Throwing Errors
Post by: gile on December 02, 2018, 04:12:08 PM
Hi,

AFAIK there's no way to throw standard LISP error from .NET. You can see this topic (https://forums.autodesk.com/t5/net/how-to-cleanly-throw-an-exception-from-lispfunction/m-p/4697127#M38204) and this one (http://www.theswamp.org/index.php?topic=45841.0).
Title: Re: Throwing Errors
Post by: Grrr1337 on December 02, 2018, 04:54:49 PM
Thank you gile!
I see some nice coding in these threads.. :)

Just an additional question (as I don't have enough experience), whats more acceptable:
To compile the classes (for instance the one you posted (https://forums.autodesk.com/t5/net/how-to-cleanly-throw-an-exception-from-lispfunction/m-p/4697127#M38204)) onto a separate .dll file and then include it as reference to the main project
To add a new class within the main project (.cs) , and copy-paste the certain sub-library with all the namespaces and classes in there