-
Notifications
You must be signed in to change notification settings - Fork 27
Generate C# exception for the project #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Like other languages, the .NET should have its own exception defined for project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a custom exception class for C# bindings in the project, replacing generic Exception usage with a project-specific exception type. The implementation includes error code mapping, human-readable error descriptions, and comprehensive documentation.
- Adds a custom
{NameSpace}Exception
class with error code and message properties - Implements error name and description lookup functionality for better error reporting
- Updates error throwing logic to use the new custom exception instead of generic Exception
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
w.Writeln(" private static string FormatMessage(int errorCode, string errorMessage)") | ||
w.Writeln(" {") | ||
w.Writeln(" string errorName = GetErrorName(errorCode);") | ||
w.Writeln(" string errorDesc = GetErrorDescription(errorCode);") |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FormatMessage method creates duplicate code by repeating the same switch logic found in ErrorName and ErrorDescription properties. Consider reusing the existing properties instead of calling separate GetErrorName and GetErrorDescription methods.
Copilot uses AI. Check for mistakes.
w.Writeln(" {") | ||
w.Writeln(" switch (errorCode)") | ||
w.Writeln(" {") | ||
w.Writeln(" case 0: return \"SUCCESS\";") | ||
for _, errorDef := range component.Errors.Errors { | ||
w.Writeln(" case %d: return \"%s\";", errorDef.Code, errorDef.Name) | ||
} | ||
w.Writeln(" default: return \"UNKNOWN\";") | ||
w.Writeln(" }") | ||
w.Writeln(" }") | ||
w.Writeln("") | ||
w.Writeln(" private static string GetErrorDescription(int errorCode)") | ||
w.Writeln(" {") | ||
w.Writeln(" switch (errorCode)") | ||
w.Writeln(" {") | ||
w.Writeln(" case 0: return \"success\";") | ||
for _, errorDef := range component.Errors.Errors { | ||
w.Writeln(" case %d: return \"%s\";", errorDef.Code, errorDef.Description) | ||
} | ||
w.Writeln(" default: return \"unknown error\";") | ||
w.Writeln(" }") | ||
w.Writeln(" }") |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GetErrorName and GetErrorDescription methods duplicate the switch logic already present in the ErrorName and ErrorDescription properties. This creates code duplication and maintenance overhead. These static methods are unnecessary since the instance properties provide the same functionality.
w.Writeln(" {") | |
w.Writeln(" switch (errorCode)") | |
w.Writeln(" {") | |
w.Writeln(" case 0: return \"SUCCESS\";") | |
for _, errorDef := range component.Errors.Errors { | |
w.Writeln(" case %d: return \"%s\";", errorDef.Code, errorDef.Name) | |
} | |
w.Writeln(" default: return \"UNKNOWN\";") | |
w.Writeln(" }") | |
w.Writeln(" }") | |
w.Writeln("") | |
w.Writeln(" private static string GetErrorDescription(int errorCode)") | |
w.Writeln(" {") | |
w.Writeln(" switch (errorCode)") | |
w.Writeln(" {") | |
w.Writeln(" case 0: return \"success\";") | |
for _, errorDef := range component.Errors.Errors { | |
w.Writeln(" case %d: return \"%s\";", errorDef.Code, errorDef.Description) | |
} | |
w.Writeln(" default: return \"unknown error\";") | |
w.Writeln(" }") | |
w.Writeln(" }") |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you
Before merging please update the RTTI example for the C# binding, and if possible create an example for reading the exception in it.
Like other languages, the .NET should have its own exception defined for project.