如何将Oracle错误消息转换为更用户友好的消息? [英] How to convert Oracle Error Messages to more user-friendly messages?

查看:49
本文介绍了如何将Oracle错误消息转换为更用户友好的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写连接到Oracle数据库的VB.Net应用程序.

I'm writing a VB.Net application conncected to Oracle database.

当应用程序出现问题时,可以说,我尝试在不接受空值的列中插入空值,Oracle会引发一个错误,该错误将在应用程序中使用Try/Catch处理.

When something goes wrong in the application, lets say, I try to insert a null value in a column which doesn't accept null values, Oracle raises an error which is handlded in the application using Try/Catch.

错误,消息并不总是用户友好的:

The error, messages are not always user friendly:

示例 错误消息:1400,试图将NULL插入列"USER"."TABLE"."COLUMN"

Example Error Ora : 1400, An attempt was made to insert a NULL into the column "USER"."TABLE"."COLUMN"

那不是我想向用户显示的错误消息.不应期望用户看到诸如Oracle用户"或表"之类的技术人员.

That's not really the error message I would like to show to my user. The user is not expected to see the technical staff such as Oracle "user" or "table".

所以我要替换的是

  • 试图将NULL插入列"USER"."TABLE"."COLUMN"

作者

  • 应填写列"字段.

现在,如何获得专栏"?当然,我可以分析异常消息的字符串并提取Column,但是,如果我的应用程序连接到具有稍微不同的异常字符串的另一个Oracle版本,则我的应用程序将无法工作.

Now, how to get the "Column" ? Of course I can analyse the string of the exception message and extract the Column but, but if my application is connected to another version of Oracle with slightly different exception strings, my application won't work.

有人对将Oracle技术"错误消息转换为用户友好消息的类有想法吗?

Does anyone have an idea about a class to convert Oracle "technical" error messages to user-friendly messages ?

谢谢.

(Null属性只是一个示例,因此列中的 AllowDBNull = true 并不是真正的解决方案)

(The Null property is just an example, so AllowDBNull = true in a column is not really the solution)

推荐答案

这在jfrankcarr的评论中有所扩展:

This is expanding on jfrankcarr's comment a bit:

我会认为像这样的Oracle错误消息是一个例外-通常,我会对应用程序进行编码,使其在进入数据库之前进行所有可能的验证,并给出用户友好的错误消息.

I would consider Oracle error messages like this an exception - normally I'd code the application to do all the validation it can before it hits the database, and give user-friendly error messages.

然后,Oracle成为一个安全网",通过在某些错误超出应用程序的验证范围时引发异常,从而确保错误数据永远不会进入系统.因此,您需要对应用程序进行编码,以执行任何Oracle错误-例如对其进行记录,然后将其发送给IT支持,并向用户显示系统错误"消息或类似内容.

Oracle then becomes a "safety net" which ensures that bad data can never get too far into the system by raising an exception if something bad slips past the application's validation. So you'd code the application to do something with any Oracle error - e.g. log it, send it to IT Support, and show a "system error" message to the user or something like that.

这篇关于如何将Oracle错误消息转换为更用户友好的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆