为什么犯规把它写在异常文件 [英] why doesnt it write to file in exception
本文介绍了为什么犯规把它写在异常文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仍然给问题
我有以下的code。只要我在尝试{}写入罚款。但是,当有一个错误,它不会写入日志文件。不知道为什么
私有静态无效JK(字符串kName,字符串路径)
{
工作职位;
尝试
{
//运行一些功能,在这里,然后写入文件
StreamWriter的LJ =新的StreamWriter(C:\\ Lob.txt);
LJ.WriteLine(XXXXXXXXXXXX);
LJ.Close();
}
赶上(InvalidException)
{
StreamWriter的LJ =新的StreamWriter(C:\\ Lob.txt);
LJ.WriteLine(YYYYYYYYYYYYYYYY);
LJ.Close();
Console.WriteLine(错误:);
返回;
}
}
解决方案
由于在尝试的唯一事情就是写到流...这是你试图做的cacth同样的事情。为什么这项工作?
still giving problem
I have the following code. As long as I am in try { } it writes fine. But when there is an error, it doesn't write to log file. Not sure why
private static void jk(string kName, string path)
{
Job job;
try
{
// run some functions here and then write to the file
StreamWriter LJ = new StreamWriter("C:\\Lob.txt");
LJ.WriteLine("XXXXXXXXXXXX");
LJ.Close();
}
catch (InvalidException)
{
StreamWriter LJ = new StreamWriter("C:\\Lob.txt");
LJ.WriteLine("YYYYYYYYYYYYYYYY");
LJ.Close();
Console.WriteLine("Error: ");
return;
}
}
解决方案
Because the only thing in your try is writing to the stream... and that's the same thing you try to do in the cacth. Why would that work?
这篇关于为什么犯规把它写在异常文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文