Skip to content
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

ErrorCode in IscException as an enum #1145

Closed
ranger-turtle opened this issue Dec 2, 2023 · 6 comments
Closed

ErrorCode in IscException as an enum #1145

ranger-turtle opened this issue Dec 2, 2023 · 6 comments

Comments

@ranger-turtle
Copy link

I have noticed that ErrorCode property in IscException can be changed to enum to make referring to the constants more readable. However, I am not sure it is a good idea, since it may break systems depending on .NET Provider too much.

I am going to refer to this doc:
https://www.firebirdsql.org/pdfrefdocs/Firebird-2.1-ErrorCodes.pdf

@cincuranet
Copy link
Member

IscException is internal. And FbException derives from DbException where ErrorCode is defined as int anyway.

@ranger-turtle
Copy link
Author

IscException is internal. And FbException derives from DbException where ErrorCode is defined as int anyway.

Thank you for answer but end-programmers would use ErrorCode from FbException in catch (Exception) when (condition) section anyway and it would be more pleasant to read if it would be at least compared to enum.

By the way, I guess I have a better idea - I would just make the enum itself, and leave ErrorType unchanged in all classes, including FbException. End-programmer can just cast the value to int in comparisons. What do you think?

@cincuranet
Copy link
Member

Thank you for answer but end-programmers would use ErrorCode from FbException in catch (Exception) when (condition) section anyway and it would be more pleasant to read if it would be at least compared to enum.

Sure. But you would have to change it in DbException in the first place.

By the way, I guess I have a better idea - I would just make the enum itself, and leave ErrorType unchanged in all classes, including FbException. End-programmer can just cast the value to int in comparisons. What do you think?

I think the best solution would be to have something like FbErrorCodes class with bunch of fields and allow simply to compare ErrorCode to known field. That would give you the textual representation of error code as well as simplicity of using it. Something like catch (FbException ex) when (ex.ErrorCode == FbErrorCodes.FooBar).

@ranger-turtle
Copy link
Author

I think the best solution would be to have something like FbErrorCodes class with bunch of fields and allow simply to compare ErrorCode to known field. That would give you the textual representation of error code as well as simplicity of using it. Something like catch (FbException ex) when (ex.ErrorCode == FbErrorCodes.FooBar).

Fairly good idea but instead of bunch of fields, I would give one field of enum type.

@cincuranet
Copy link
Member

That would require explicit cast to enum.

@cincuranet
Copy link
Member

#1148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants