error-handling 相关问题

编程语言结构,用于处理由错误代码,异常或其他语言特定方法发出的错误。





括号,圆形支架括号和逗号

#here is my code people = ["the boogie man"] while True: item = input("Enter a person (or 'q' to quit): ") if item.lower() == 'q': break people.append(item) print(people) import random person = (*random.sample(people, k=1),) #trying to get rid of the extra stuff person1 = (*random.sample(people, k=1),) person2 = (*random.sample(people, k=1),) person3 = (*random.sample(people, k=1),) Locations = ["the lagoon", "the basement", "the dark forest", "the kitchen", "the backyard", "the batcave"] weights = [1, 1, 1, 1, 1, 1] location = random.choices(Locations, weights=weights, k=1)[0] Weapons = ["flintlock pistol", "shotgun", "AK-47", "steak knife", "butter knife", "fork", "infant child", "batman"] weights = [1, 1, 1, 1, 1, 1, 1, 1] weapon = random.choices(Weapons, weights=weights, k=1)[0] cod = ["poisioned bagels", "a seigure", "a todler with a plastic spoon", "slippery floor sign not being on the slippery floor"] weights = [1, 1, 1, 1] causeofdeath = random.choices(cod, weights=weights, k=1)[0] messages = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"] weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] message = random.choices(messages, weights=weights, k=1)[0] if message == "1": print(str(person) + " killed " + str(person1) + " with a " + weapon + " and hid the body in " + location) if message == "2": print(str(person) + " saved " + str(person1) + " from " + str(person2) + " who was trying to kill them using a " + weapon) if message == "3": print(str(person) + " swears they are innocent") if message == "4": print(str(person) + " paid " + str(person1) + " to kill " + str(person2) + " with a " + weapon) if message == "5": print(str(person) + " framed " + str(person1) + " for " + str(person2) + "'s murder")

回答 1 投票 0

从sqlalchemy+postgres

一些类型的约束最好由数据库检查,因为试图手动检查它们可能会导致比赛条件。 那么,您会认为数据库驱动程序将使这个简单,正确...

回答 2 投票 0


返回错误,而不是从python capi

是否是一个好主意(这可能被认为是不良的实践),有时我会在Python中返回错误而不是提出错误。 def fna(Some_param): #在复杂...

回答 1 投票 0


如何解析mysql错误

我读了一些文章,例如thisOne

回答 2 投票 0

犯错,引发错误

关于错误的问题也有类似的问题,X并未捕获所有错误等,但是我遇到了一个不同的问题。 我的(经典ASP)页面效果很好,大多数时候。一些用户抱怨

回答 1 投票 0


使用Spotify API检索轨道数据

sp.playlist_tracks(playlist_id=playlist_uri)['items']

回答 1 投票 0


RESTAPI错误代码500处理

我们正在建立一个新的REST API。 我认为错误代码500(内部服务器错误)永远不应返回。 现在,当然,如果您知道客户的参数是错误的,或者您拥有的东西

回答 3 投票 0

我不是我在做什么错,而是没有错误。CaptureStackTrace-堆栈跟踪是相同的。 我想知道使用CaptureStackTrace的当前状态,因为我认为没有区别:-)以及似乎不再需要的Verror。

class MyErrorOne extends Error { constructor(message) { super(message); Error.captureStackTrace(this, this.constructor); } } class MyErrorTwo extends Error { constructor(message) { super(message); Error.captureStackTrace(this, this.constructor); } }

回答 3 投票 0

节点UTILS检查功能真的是弹力的证明,而且永远不会引发异常?

从此代码开始 const输入:未知//可能是任何类型的未知输入 尝试 { //试图将其扔掉可能会扔掉(例如,用于循环引用)

回答 1 投票 0

我如何在php中修复“未定义变量”错误? today,我已经开始学习PHP。而且,我创建了第一个PHP文件来测试不同的变量。您可以看到我的文件如下。

我在浏览器中运行此文件时发现了以下错误。 notice:未定义的变量:x in/opt/lampp/htdocs/anand/php/php/index.php in19行 NOTICE:未定义的变量:y in/opt/lampp/htdocs/anand/php/php/index.php在第29行上 我如何解决有关它的问题? 第一个错误(不确定)是因为默认情况下没有将全球范围导入到功能中(而不是“超级全球”,那是)。 您需要告诉您的功能您是在引用全局变量$x:: $x php,PHP无法判断您是否正在用同名局部变量遮蔽全局变量。 第二误差(function myTest() { global $x; // $x refers to the global variable $y=10; // local scope echo "<p>Test variables inside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; } 是未定义的),是因为本地范围就是本地。它的全部要点是$y不会从功能中“泄漏”。当然,您无法以后在代码中访问$y在定义其定义的函数之外。如果可以的话,它与全球没有什么不同。 $y 您正在遇到第一个错误,因为变量$ a无法访问全局变量的值,除非您明确声明函数内部声明。 示例#1使用全局 <?php $a = 1; /* Global scope */ function test() { echo $a; /* Reference to local scope variable */ } test(); ?> 以及您遇到的最后一个错误是因为$y在函数内定义了global $a,因此其范围仅限于该函数。 对于详细的解释,请阅读宽可变范围。 有两种使用变量globally:的情况 使用该变量的单个副本并从任何地方进行修改,即从函数内部或外部进行修改,即在全局范围内进行修改。在这种情况下,您需要在允许的函数集<?php $a = 1; $b = 2; function Sum() { global $a, $b; // If you want to access a global variable, // you have to use the 'global' keyword $b = $a + $b; } Sum(); echo $b; ?> 形式中声明。 在情况下,您需要使用用于全局变量的same标识符的单个函数的局部变量(即所有函数之外的变量);在这种情况下,您有两个变量具有相同名称,即该功能一个本地和一个全局。然后,您需要使用superglobal变量mytest()即所有全局变量的数组。我个人更喜欢这种方法来制作高效代码; 以下是两者的代码。 代码1(使用全局声明) global $x; 代码2(使用$ GLOBALS []数组) $GLOBALS SET$ x作为全球,喜欢 <?php $x = 5; // Global scope function myTest() { $y = 10; // Local scope global $x; echo "<p>Test variables inside the function:<p>"; echo "Variable x in global scope is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest(); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 或尝试以下操作: <?php $x = 5; // Global scope function myTest() { $y = 10; // Local scope $x = 23; echo "<p>Test variables inside the function:<p>"; echo "Variable x in global scope is: " . $GLOBALS['x']; echo "<br>Variable x in local scope is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest(); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 代码的行为是按预期的,但是如果您想在脚本上使用两个变量,请使用以下方式: global $x; 在php中,如果要在该函数中使用函数,则必须在函数中声明全局变量。 <?php $x = 5; // Global scope function myTest($x) { $y=10; // Local scope echo "<p>Test variables inside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest($x); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 通过在函数中宣布$ x全局,它将参考变量的全局版本。 您必须学习PHP中变量的范围。请参阅VariableScope. 在您的代码中,$ x是一个全局,因此,为了在函数开头访问函数中的该变量,即,即,即 <?php $x = 5; // Global scope function myTest(){ global $x; global $y; $y = 10; echo "<p>Test variables inside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest(); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 对于$ y,您要么通过检查isset($ y)跳过输出,要么在全局范围内分配默认值。 upput $ x在“ echo”中的“”中的“”中的“变量” $ x是:”。$ x; yii ase \ errorexception:undefined变量$启动in/var/www/tracktraf.online/frontend/frontend/controllers/telegramcontroller.php:197 堆栈跟踪: #0/var/www/tracktraf.online/frontend/controllers/telegramcontroller.php(197):yii ase \ errorhandler-> thanherror() #1 [内部功能]:前线

回答 4 投票 0

将特定的警告类型转化为错误

考虑以下代码: > df<- tibble(gender=c(1,1,0)) >df $男性 警告:未知或不可传剂的专栏:“男性”。 无效的 如何将此特定的警告类型转换为错误? 我...

回答 2 投票 0

固定拥抱面部登录问题(504 Gateway超时和无效令牌错误)

is 我试图登录到拥抱Face CLI,但我一直遇到以下错误: requests.exceptions.httperror:504服务器错误:URL的网关超时:https://huggingface.co/api/whoam...

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.