标签: error-handling

是否有可能在包含文件中捕获致命错误php?

这就是我想要做的事情,如果文件中有致命错误我不希望脚本停止执行

try { 
require "somethin.php"
} catch(...) {}
Run Code Online (Sandbox Code Playgroud)

会有一些方法file_get_contents()并且eval()可以解决这个问题

php error-handling include

0
推荐指数
2
解决办法
1600
查看次数

C#错误:并非所有代码路径都返回一个值.将字符串转换为浮点数

我正在编写一个程序,从文件中读取数据集并将其转换为变量.我遇到了一个问题,我的转换方法(将数组中的字符串转换为浮点数)因为我不断得到"并非所有代码路径返回值"错误.有谁知道我怎么能解决这个问题?

这是我的代码:

    public float Get_Value(string line)
    {
        float dataValue;
        // Searching for block containing data value
        string[] lineset = splitline(line);
        string valueString = lineset[2];
        try
        {
            dataValue = float.Parse(valueString, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
        }
        catch
        {
            MessageBox.Show("invalid data");
            dataValue = -9999999999;
        }
    }
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助

c# floating-point methods error-handling visual-studio-2010

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

Yii错误摘要默认消息更改

您好,我对Yii框架不是很熟悉,有人可以告诉我如何更改默认的errorSummary消息吗?我已经看过Yii指南,让我很困惑.我需要在模型中添加什么以及在视图中需要什么?谢谢

php error-handling yii

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

错误:"进程无法访问....因为它正被另一个进程使用."在"删除图像"中

我知道其他人有类似的问题,但我的问题是针对图像...我有一个像下面的图像功能:

        static public string Setimage(PictureBox pictureBox, OpenFileDialog ofd,string nameform,string folderform)
    {
        ofd.Title = "Select Pictures";
        ofd.Filter = "Pictures(*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png | All file (*.*)| *.*";

        ofd.DefaultExt = ".jpg"; // Default file extension 
        string namefile = "";
        // Process open file dialog box results 

        if (ofd.ShowDialog() == DialogResult.OK)
        {
           // try
            //{
                string fileName = ofd.FileName;
                if (ofd.SafeFileName.Length <= 50)
                    if (Image.FromFile(fileName).Width >= 640 && Image.FromFile(fileName).Height >= 480)
                    {
                        namefile = ofd.SafeFileName;
                        if …
Run Code Online (Sandbox Code Playgroud)

c# error-handling

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

用python中的函数解压缩的值太多了?

我有这样的文字:

text = ["A/abc","B/abd","C/abc","D/xyz"]
Run Code Online (Sandbox Code Playgroud)

我想要的输出是

 mylist1 = ["A","C"]
 mylist2 = ["B"]
 mylist3 = ["D"]
Run Code Online (Sandbox Code Playgroud)

我正在寻找的唯一标签是"/ abc"和"/ abd"

现在我拥有的是:

def searchWord(segment):
    word_tag = segment.split('/')

    if re.finditer('ab',word_tag[1]):
        if re.finditer('abc',word_tag[1]):
            letter = word_tag[0]
            mylist1 = letter
        else:
            letter = word_tag[0]
            mylist2 = letter
    else:
        letter = word_tag[0]
        mylist3 = letter

    return mylist1
    return mylist2
    return mylist3

mylist1,mylist2,mylist3 = [searchWord(segment) for segment in text]
Run Code Online (Sandbox Code Playgroud)

它似乎工作正常,但抛出异常:

 ValueError: too many values to unpack.
Run Code Online (Sandbox Code Playgroud)

我的"文本"列表相当大,这可能是问题吗?在为此过程构建函数之前,我没有遇到此问题.

谢谢!

python error-handling list

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

MVC验证建议

我目前正在验证输入并在"胖控制器"中返回错误,如下所示:

class SomeController
{
    public function register()
    {
        // validate input
        $username = isset($_POST['username']) && strlen($_POST['username']) <= 20 ? $_POST['username'] : null;

        // proceed if validation passed
        if (isset($username)) {
            $user = $this->model->build('user');
            if ($user->insert($username)) {
                $_SESSION['success'] = 'User created!';
            } else {
                $_SESSION['error'] = 'Could not register user.';
            }
        } else {
            $_SESSION['failed']['username'] = 'Your username cannot be greater than 20 characters.';
        }

        // load appropriate view here
    }
}

class SomeModel
{
    public function insert($username)
    {
        // sql …
Run Code Online (Sandbox Code Playgroud)

php validation error-handling model-view-controller

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

Python:另一个'NoneType'对象没有属性错误

对于新手练习,我试图在html文件中找到元标记并提取生成器,所以我喜欢这样:

Version = soup.find("meta", {"name":"generator"})['content']
Run Code Online (Sandbox Code Playgroud)

因为我有这个错误:

TypeError: 'NoneType' object has no attribute '__getitem__'
Run Code Online (Sandbox Code Playgroud)

我以为使用异常会纠正它,所以我写道:

try: Version = soup.find("meta", {"name":"generator"})['content']

except NameError,TypeError:

     print "Not found"
Run Code Online (Sandbox Code Playgroud)

而我得到的是同样的错误.

那我该怎么办?

python error-handling beautifulsoup

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

如何将Ruby的write_nonblock/read_nonblock与服务器/客户端一起使用?

我正在尝试将Ruby与服务器一起使用.我从玩家那里得到一个输入或一个字符串,这样服务器就会玩一场战争(纸牌游戏).

真正令人沮丧的是我正在使用read和write_nonblock,并且我一直遇到错误,我不知道它们为什么会出现,因此不知道如何解决它们.

Errno::EAGAIN: Resource temporarily unavailable - read would block #etc. etc. 
Run Code Online (Sandbox Code Playgroud)

那么......我如何在服务器和客户端上正确使用读写non_block来发送和接收数据(所以我可以触发事件)?(我是一个新的程序员,所以解释越简单越好.)

ruby error-handling iostream nonblocking send

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

如果发生Javascript错误,则显示警告或弹出窗口

如果我收到Javascript错误,是否可以通知visuel?

在开发中我有Firebug或其他东西打开所以我发现它.但是,如果我为别人做一个轻微的演示,我就不能打开它.

我仍然更喜欢知道错误,而不是默默地失败,我不知道跟踪错误,我无法区分真实错误和尾随错误.

javascript error-handling warnings

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

为什么"strcat已在***.obj中定义"?

我只用#include <stdio.h>

#include <stdio.h>

void strcat(char* s, char* t);

int main()
{
    char str1[12] = "hello";
    char str2[] = ",world";
    strcat(str1, str2);
    printf("%s\n", str1);
    return 0;
}

void strcat(char* s, char* t)
{
    int i = 0, j = 0;
    while(*s != '\0')
        i++;

    while((*(s + i++) = *(t + j++)) != '\0');

}
Run Code Online (Sandbox Code Playgroud)

但是当我构建它时,控制台输出:

--------------------Configuration: test16 - Win32 Debug--------------------
Linking...
LIBCD.lib(strcat.obj) : error LNK2005: _strcat already defined in test16src.obj
Run Code Online (Sandbox Code Playgroud)

为什么?不strcat中不存在stdio.h

PS:您能否通过描述与其他文件链接的进度来解释链接错误?

c error-handling stdio strcat

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