Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Resolved Visual Scripting - How to catch system exceptions

Discussion in 'Authoring Dev Blitz Day 2023' started by Marou1, Jan 26, 2023.

  1. Marou1


    Dec 13, 2021

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

    Code (CSharp):
    1. try
    2. {
    3. SaveData(data);
    4. }
    5. catch(System.IO.IOException)
    6. {
    7. DisplayMessage("The file is open elsewhere or there is not enough storage space");
    8. }
    9. catch(System.Security.SecurityException)
    10. {
    11. DisplayMessage("Could not save as you do not have the required permissions");
    12. }

    Basically I need to catch these 4 exceptions:

    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.

  2. jeanedouard_unity


    Unity Technologies

    May 2, 2019
    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.
    Marou1 likes this.