我自己的错误信息 [英] My Own Error Messages
问题描述
我制作了一个简单程序,可以编辑文本文档.它使用类库调用Text.dll
.
在发布我的应用程序之后,打开已发布的文件夹,那里有2个文件,一个是TextEditor.exe
,另一个是Text.dll
. (Text.dll用于写入/读取txt文件)
当我删除Text.dll
时,运行该应用程序并尝试保存一个文本文件.但这从.Net FrameWork
给了我系统错误.如何将其转换为我的消息?
I have made a Simple Program, which edits Text Documents. It uses A class library call Text.dll
.
After I publish my Application, And open the published folder there''re 2 file, One is TextEditor.exe
and the other one is Text.dll
. (Text.dll is used to write/read txt files)
When I delete the Text.dll
, run the application and try to save a text file. But It gives me a system Error from .Net FrameWork
. How Can I Convert That to a message of mine ?
推荐答案
使用CustomErrors标签
asp.net中的自定义错误"
Use CustomErrors tag
custom errors in asp.net"
您应该使用try-catch块或在开始时检查文件的存在.您可以在Google或MSDN网站上找到try-catch块的用法,因此我在这里不做解释.
使用文件检查应执行以下操作:
1)打开项目
2)在事件代码中写
You should either use try-catch blocks or check the existance of file at the starting point. You can find the use of try-catch block on google or MSDN site so i will not explain it here.
Use of file checking should do:
1) Open Project
2) in the event code write
if (File.Exists(filePath)){
Application.Run(new StartForm);
}
else
{
MessageBox.Show("File not found");
}
那应该为您解决.
或者您也可以尝试使用try catch块.
That should work out for you.
or you can do the same with try catch block.
这篇关于我自己的错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!