As others have already explained, your question is already an "OK" question. Thus, I will focus on how to make it a great question.
Include a minimal reproducible example.
Your example is not minimal. At a first glance, at least one of the catch
lines can be removed, and the error will still occur. The same is probably true for a lot of the other lines of Port_Setting()
. Once you start down that road, you will probably identify which particular exception is thrown, and that all that "convert an exception to an error code" logic is not necessary to reproduce the problem.
Once your example is minimal (nothing can be removed or simplified without the problem disappearing), your question will be both more interesting and easier to read, and, thus, more favorably received by the community: You will have already identified where exactly the error occurs, so the SO crowd can use their expertise to explain why it occurs and what you can do to fix it (which is something many people here like to do), rather than having to debug your code (which is something many people here don't like to do).
Setting Error
was the literal error output OP referenced (I was thinking "this guy has edited half a dozen times and still hasn't put the error message in the question?"). Once I re-read the question & read the revisions, I actually bookmarked the question to undelete vote later, upvoted the Q, and made an edit to the answer to improve (IMO) the readability of it. Not the first time I have wished we had the ability to retract delete/undelete votes.site@stackoverflow.com c# form designer base events
got me pretty close.