创建 C# 验证类的好方法
我有上传文件、验证文件、将其保存到数据库等功能。
所有这些操作都针对一些不同的类和方法。但是,如果这些方法中的任何一个出现问题,我想将这些错误通知给我的前端。
有没有一种好的方法来管理这个问题,我们称之为“错误类”?
谢谢!
I have a functionality that upload a file, validate it, save it to database and so on.
All of these actions are on some different classes and methods. But, if something goes wrong in any of these methods, I want to inform these errors to my front-end.
Is there a good way to manage this, let's call, "Error Class"?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以采取的一种方法是创建“错误类”,就像应用程序中的服务一样,并发布执行各种操作的不同类和方法可能会向其发布错误。
现在,您的前端可以订阅“错误类”以立即了解错误,也可以返回错误代码,可以使用“错误类”找到详细信息
One approach that you could take would be to create the "Error Class" like a service in your application and post the different classes and methods that perform various actions could post errors to it.
Now your front-end can either subscribe with the "Error Class" to know of errors immediately or you could return an error code the details of which can be found using the "Error Class"
好吧,可以说,您处理文件的顺序是
现在,在所有这些序列中,如果它始终相同,那么您可以采用异常抛出机制并在前端收集它。也许你可以抛出一个错误 ID。
Well lets say, your sequence of processing a file is
Now, in all these sequence if its same all the time, then you could just go for exception throwing mechanism and collect it at the front end. May be you could throw with an Error ID.