标签: error-handling

这个简单的C代码有什么问题?

#include <stdio.h>

int main()
{
    int m,n; scanf("%d %d",&m,&n);
    char ar[m][n];
    char buf[n];
    int a,b;
    for(a=0;a<m;a++)
    {
        gets(buf);
        for(b=0;b<n;b++) ar[a][b] = buf[b];
    }
    for(a=0;a<m;a++,printf("\n")) for(b=0;b<n;b++) printf("%c",ar[a][b]);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

此代码从m行作为输入stdin,每行包含n个字符,并打印所有行stdout.就那么简单.但似乎存在内存泄漏,因为gets(buf)遇到第一次,它的执行被跳过.

我也在C++中尝试过,认为内存泄漏会消失.这是代码:

#include <cstdio>
using namespace std;

int main()
{
    int m,n; scanf("%d %d",&m,&n);
    char **ar = new char*[m];
    char *buf = new char[n];
    int a,b;
    for(a=0;a<m;a++)
    {
        gets(buf);
        ar[a] = new char[n];
        for(b=0;b<n;b++) ar[a][b] = buf[b];
    }
    for(a=0;a<m;a++,printf("\n")) for(b=0;b<n;b++) printf("%c",ar[a][b]); …
Run Code Online (Sandbox Code Playgroud)

c error-handling memory-leaks

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

正则表达式C#控制台应用程序

如何添加一个接受小数位(5.23)的正则表达式,但是在这样的中断中没有其他内容?即只处理数字和小数位,如果键入或返回除此之外的任何内容,则会抛出错误:

    case 1:
    double[] myArrai1 = new double[3];
    Console.WriteLine("Insert a number");
    myArrai1[0] = double.TryParse(Console.ReadLine()); // no overload method?
     Console.WriteLine("Insert a number");
     myArrai1[1] = double.Parse(Console.ReadLine());
    Console.WriteLine("Insert a number");
    myArrai1[2] = double.Parse(Console.ReadLine());
    break;
Run Code Online (Sandbox Code Playgroud)

干杯伙计们.

Ps不确定如何使用中断编程也必须毫无例外.

c# regex error-handling

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

ex.class应该在这里等于什么?

我正在尝试使用从本网站下载的代码来学习ruby .

我陷入了困境.

  def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
    # What happens when you call a method that doesn't exist.  The
    # following begin/rescue/end code block captures the exception and
    # makes some assertions about it.
    begin
      nil.some_method_nil_doesnt_know_about
    rescue Exception => ex
      # What exception has been caught?
      assert_equal NoMethodError, ex.class

  # What message was attached to the exception?
  # (HINT: replace __ with part of the error message.)
  assert_match(/__/, ex.message)
end
Run Code Online (Sandbox Code Playgroud)

结束

我应该用错误消息的一部分替换__,但我没有成功.好吧,我是,因为经过几次尝试后我只是用空格替换它,因为我认为错误信息在单词之间有空格.但我怎么看错误信息是什么?

ruby methods error-handling exception-handling exception

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

奇怪的向量<long>加上'0'为'-1'

我正在写一个基本的国际象棋程序来计算你可以用给定的国际象棋数字制作多少套.数据文件:

4
22 3 5 6 2 0
1 1 1 1 1 1
8 4 4 4 1 2
5 3 3 3 0 2
Run Code Online (Sandbox Code Playgroud)

代码:

#include <iostream>
#include <fstream>
#include <vector>

int main
(int argc, char *argv[])
{
    std::fstream data_file;
    size_t i, k;
    std::vector<long> chess;
    long t, n;

    data_file.open("U1.txt", std::ios::in);

    data_file >> n;

    for (i = 0; i < n; i++)
        chess.push_back(0);

    for (i = 0; i < n; i++) {
        for (k = 0; k < 6; …
Run Code Online (Sandbox Code Playgroud)

c++ debugging error-handling

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

C#Windows Phone Mango - 无效的跨线程访问?解析XML

我有以下代码似乎抛出"无效的跨线程访问".而我似乎无法弄清楚为什么.我正在从URL加载远程xml文件,但是,在解析该XML时,我总是收到此错误.有什么建议?

using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
        {
            string xml = streamReader.ReadToEnd();

            using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
            {

                    reader.ReadToFollowing("channel");
                    reader.MoveToFirstAttribute();

                    reader.ReadToFollowing("title");
                    output.AppendLine("Title: " + reader.ReadElementContentAsString());

                    reader.ReadToFollowing("description");
                    output.AppendLine("Desc: " + reader.ReadElementContentAsString());

                    textBox1.Text = output.ToString(); //Invalid cross-thread access.
            }

        }
Run Code Online (Sandbox Code Playgroud)

我试图解析的XML如下所示,我只是在尝试解析点点滴滴,因为我继续学习如何使用c#来解析不同类型的XML:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"xmlns:dc="http://purl.org   /dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0  /modules/slash/">
  <channel>
<title>Server &amp; Site News</title>
<description>A place for the Admin and Moderators to post the latest news on both the server and site.</description>
<pubDate>Fri, 18 May 2012 22:45:08 +0000</pubDate>
<lastBuildDate>Fri, 18 …
Run Code Online (Sandbox Code Playgroud)

c# xml url error-handling windows-phone-7

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

严格标准:is_a():已弃用.请使用instanceof运算符

我正在使用cakephp 2.0.我已经将用户登录与xenforo集成在一起但在完成后我正在进行任何操作,如添加,编辑,删除视图不重定向,$this->redirect不起作用.

我收到此错误:

严格标准:is_a():已弃用.请使用instanceof运算符......

谢谢

php error-handling cakephp cakephp-2.0

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

ios检查空对象

我通过引用在线找到的一些代码传递了一个错误.该错误作为空对象返回,意味着没有错误.

如果我检查error.code我得到一个糟糕的访问,因为该对象是空的.

如果我检查error == nil我得到一个假,因为error是一个空对象.

如何使用逻辑来查找错误,但是为空?

error-handling nserror ios

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

如何表明某个类不支持某些运算符?

我正在写一个代表顺序尺度的类,但没有逻辑零点(例如时间).这个规模应该允许加法和减法(operator+,operator+=,...),但无法繁殖.

然而,我总觉得这是一个很好的做法,当一个人重载一个特定组的一个操作符(在这种情况下是数学运算符)时,还应该重载属于该组的所有其他操作符.在这种情况下,这意味着我还需要重载乘法和除法运算符,因为如果用户可以使用,A+B他很可能期望能够运行其他运算符.

有没有一种方法可以用来在编译时为此抛出错误?最简单的方法就是不要重载操作符operator*,......但是添加更多的解释似乎是合适的operator* is not know for class "time".

或者这是我真的不应该关心的事情(RTFM用户)?

c++ error-handling compiler-errors operator-overloading

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

PHP错误处理 - "错误的ErrorHandler参数"

我正在尝试第一次设置错误处理.
它实际上工作并报告错误(如果有),但由于某种原因,它总是显示错误处理函数本身的"缺少参数"的错误.请注意我的错误处理函数是在一个单独的文件中并包含在索引页面中,我不确定这是否是问题:S

这是我的错误处理功能

function errorHandler($errno, $errstr, $error_file, $error_line) {

  if(isset($errstr)) {
    # There is an error, display it
    echo $errno." - ".$errstr." in ".$error_file." at line ".$error_line."<br>";
  } else {
    # There isn't any error, do nothing
    return false;
  }

}

// We must tell PHP to use the above error handler.
set_error_handler("errorHanlder");
Run Code Online (Sandbox Code Playgroud)

这是索引页面

<!-- # Error Handler -->
<? if(errorHandler()) { ?>
<section id="error-handler">
  <?=errorHandler();?>
</section>
<? } ?>
Run Code Online (Sandbox Code Playgroud)

这是浏览器中的结果(请记住没有php错误,所以这个错误处理程序不应该输出任何东西 - 这是我无法理解的

2 - Missing argument 1 for errorHandler(), …
Run Code Online (Sandbox Code Playgroud)

php error-handling function

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

需要了解这个新错误的含义?

这是一个.NET错误:

Error Message: String was not recognized as a valid Boolean.
Error Source : mscorlib
Run Code Online (Sandbox Code Playgroud)

这可能有点神秘,但这就是我必须展示的.如何回顾所发生的事情...我真的需要帮助,如果之前没有出现过这种情况怎么会出现,尽管应用程序是相同的.谢谢

.net c# debugging error-handling

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