相关疑难解决方法(0)

宇宙射线:它们对程序产生影响的概率是多少?

我再一次进行了设计评审,并且遇到了一个声称特定情景的概率"低于宇宙射线的风险"影响该程序的说法,并且我发现我没有最微弱的想法是什么概率是.

"因为2 -128是340282366920938463463374607431768211456中的1个,我认为我们在这里抓住机会是合理的,即使这些计算已经减少了几十亿......我们对宇宙射线的风险更大我相信,把我们搞砸了."

这个程序员是否正确?宇宙射线撞击计算机并影响程序执行的概率是多少?

statistics physics probability error-detection risk-analysis

529
推荐指数
14
解决办法
5万
查看次数

如果我在Try块中返回一个值,那么finally语句中的代码会触发吗?

我正在为一位朋友审查一些代码,并说他在try-finally块中使用了一个return语句.即使try块的其余部分没有,Finally节中的代码是否仍会触发?

例:

public bool someMethod()
{
  try
  {
    return true;
    throw new Exception("test"); // doesn't seem to get executed
  }
  finally
  {
    //code in question
  }
}
Run Code Online (Sandbox Code Playgroud)

.net c# exception-handling try-catch

228
推荐指数
7
解决办法
7万
查看次数

最终没有在.net中执行的条件try..finally阻止

基本上我听说某些条件会导致.net超越finally块.有谁知道这些条件是什么?

.net exception-handling

46
推荐指数
3
解决办法
1万
查看次数

在try/catch/finally中"finally"的目的是什么

语法将从语言变为语言,但这是一个普遍的问题.

这有什么区别....

try
{
     Console.WriteLine("Executing the try statement.");
     throw new NullReferenceException();
}
catch (NullReferenceException e)
{
     Console.WriteLine("{0} Caught exception #1.", e);
}       
finally
{
     Console.WriteLine("Executing finally block.");
}
Run Code Online (Sandbox Code Playgroud)

还有这个....

try
{
    Console.WriteLine("Executing the try statement.");
    throw new NullReferenceException();
}
catch (NullReferenceException e)
{
    Console.WriteLine("{0} Caught exception #1.", e);
}        
Console.WriteLine("Executing finally block.");
Run Code Online (Sandbox Code Playgroud)

我一直看到它被使用,所以我认为有一个很好的理由最终使用,但我无法弄清楚它是如何只是在声明之后放置代码,因为它仍然会运行.

有没有最终没有运行的场景?

javascript c# exception-handling finally

21
推荐指数
3
解决办法
5109
查看次数

试着抓住最后的问题

在Try Catch Finally块中,finally块总是执行,无论是什么,或者只有catch块没有返回错误?

我的印象是,如果catch块没有错误,则finally块只会执行.如果由于错误而执行了catch块,那么它是否应该一起停止执行并返回错误消息(如果有的话)?

c# exception-handling

17
推荐指数
3
解决办法
1万
查看次数

代码最终会在重定向后运行吗?

以下面的代码为例:

   try
   {
      Response.Redirect(someurl);
    }
    finally
    {
       // Will this code run?
    }
Run Code Online (Sandbox Code Playgroud)

finally块中的代码会运行吗?

c# asp.net

8
推荐指数
4
解决办法
3208
查看次数


是否存在垃圾收集器由于异常而无法运行的情况?

出于好奇,我想知道是否有可能出现垃圾收集器无法运行或根本不运行的情况(可能是由于异常)?

如果是,很可能会出现OutOfMemory/Stackoverflow异常.那么在这种情况下,仅通过查看异常消息,stacktrace等,我们就可以确定gc未能运行的核心问题.

c# garbage-collection

4
推荐指数
1
解决办法
969
查看次数

在try finally块中记录异常详细信息

我有一小段代码调用webservice客户端方法.

该方法返回一个消息数组作为out参数.这些消息通常包含已发生的任何错误的详细信息.发生错误时,也会引发异常.

我想记录消息,无论是抛出异常还是异常类型.登录finally块是否可以接受?

WebServiceClient client = GetWebServiceClient();
Console.WriteLine("Calling getUpdates...");
ItemStatus[] itemStatuses;
Message[] messages = null;
string outToken;
try
{
     outToken = client.getUpdates(inToken, out itemStatuses, out messages);
}
finally
{
     LogMessages(messages);
}
Run Code Online (Sandbox Code Playgroud)

.net c# logging exception

4
推荐指数
1
解决办法
1047
查看次数

是否存在finally块未执行的任何情况?

请注意以下代码:

 class CTestFinally
  {
      public static void Run()
      {
          try
          {
              TryAndTry();
          }
          catch (Exception exError)
          {
              Console.WriteLine(exError.Message);
          }
          finally
          {
              Console.WriteLine("Finally...!");
          }
          Console.ReadKey();
      }

      static void TryAndTry()
      {
          try
          {
              TryAndTry();
          }
          catch (Exception exError)
          {
              Console.WriteLine(exError.Message);
          }
          finally
          {
              Console.WriteLine("Try: Finally...!");
          }
          }
}
      }
Run Code Online (Sandbox Code Playgroud)

最后从未执行因为我们得到堆栈溢出错误.

除了上述问题之外,还有哪种情况下finally块不会被执行?

c#

2
推荐指数
1
解决办法
223
查看次数

最后在Python中添加只是为了更好的可读性

在此链接(https://docs.python.org/2/tutorial/errors.html#defining-clean-up-actions)下面说:

在离开try语句之前总是执行finally子句,无论是否发生了异常.

代码1:

try:
    print "Performing an action which may throw an exception."
except Exception, error:
    print "An exception was thrown!"
    print str(error)
else:
    print "Everything looks great!"
finally:
    print "Finally is called directly after executing the try statement whether an exception is thrown or not."
Run Code Online (Sandbox Code Playgroud)

输出1:

Performing an action which may throw an exception.
Everything looks great!
Finally is called directly after executing the try statement whether an exception is thrown or not.
Run Code Online (Sandbox Code Playgroud)

代码2:

try:
    print "Performing …
Run Code Online (Sandbox Code Playgroud)

python exception-handling exception

0
推荐指数
1
解决办法
53
查看次数