首页 \ 问答 \ 在try / python除外之后停止运行程序(Stop program from running after try / except python)

在try / python除外之后停止运行程序(Stop program from running after try / except python)

我做了一个程序,它从treeview中获取值,并在按下按钮时计算一些东西。 我把try / except语句放在那个函数里面。

def SumAll():
    try:
       #do something (calculate)

    except ValueError:

        Error=messagebox.showinfo("Enter proper values")
        pass

问题是,当messagebox.showinfo出现时,程序会继续运行,并且会给出ValueError 。 我该如何解决这个问题,以及如何将多个错误异常( IndexError等)?


I made a program that takes values from treeview and calculate something when button is pressed. I put try / except statement inside that function.

def SumAll():
    try:
       #do something (calculate)

    except ValueError:

        Error=messagebox.showinfo("Enter proper values")
        pass

The problem is, program keeps running when messagebox.showinfo appears, and it gives the ValueError. How can I fix that, and how can I put more than one error exception (IndexError, etc)?


原文:https://stackoverflow.com/questions/49953598
更新时间:2024-04-23 21:04

最满意答案

由于您希望通过电子邮件发送HTML表格,因此您只需创建一个HTML表格,并在每次出错时添加一些行。 然后将其包含在您的电子邮件内容中并发送邮件。

$users = mysqli_query($con, "SELECT * FROM table");

// Table header
$htmlError = '<table><tr><th>ID</th><th>Column 1</th><th>Column 2</th></tr>';

while($row = mysqli_fetch_array($users)) {

    if  ($row['column1'] !=  $row['column2']) {
        // Add new row to table
        $htmlError .= '<tr><td>'.$row['id'].'</td><td>'.$row['column1'].'</td><td>'.$row['column2'].'</td></tr>';
    }
}

// End table
$htmlError .= '</table>';

// Send mail
...

As you want to send an HTML table by email, you just have to create an HTML table and add some lines each time you have an error. Then include it into your email's content and send the mail.

$users = mysqli_query($con, "SELECT * FROM table");

// Table header
$htmlError = '<table><tr><th>ID</th><th>Column 1</th><th>Column 2</th></tr>';

while($row = mysqli_fetch_array($users)) {

    if  ($row['column1'] !=  $row['column2']) {
        // Add new row to table
        $htmlError .= '<tr><td>'.$row['id'].'</td><td>'.$row['column1'].'</td><td>'.$row['column2'].'</td></tr>';
    }
}

// End table
$htmlError .= '</table>';

// Send mail
...

相关问答

更多