Visual Scripting - How to catch system exceptions

Hello,

I want to catch system exceptions to do something like this:

Code (CSharp):

  • try
  • {
  • SaveData(data);
  • }
  • catch(System.IO.IOException)
  • {
  • DisplayMessage(“The file is open elsewhere or there is not enough storage space”);
  • }
  • catch(System.Security.SecurityException)
  • {
  • DisplayMessage(“Could not save as you do not have the required permissions”);
  • }

Basically I need to catch these 4 exceptions:
System.IO.IOException
System.Security.SecurityException
System.FormatException
System.ArgumentException

I added System Exception in the nodes in Project Settings, but I cannot find these exceptions. Also, I am not sure how to use the Try&Catch node.

Thanks

To add an Exception type just go to the Visual Scripting Project Settings and add it to the Type options list. After clicking on the Regenerate Nodes button you should be able to see the nodes related to the exception type you just added.
Now for the try/catch node, unfortunately there seems to be an issue as after trying on version 1.8.0, I can’t get the exception types displayed in the dropdown menu of the node. I’ll log that issue and make sure to prioritize this for the next VS update.

1 Like