我试图返回 R 函数中的任何实际错误消息,并向其发送电子邮件以通知用户,但它仅打印 R 参数中的自定义消息。有什么办法可以在电子邮件中发送实际的错误消息吗?
以下是我迄今为止编写的虚拟脚本:
mailme <- function(message){
#function to send email
}
b<-function(){
r <- NULL
attempt <- 1
while( is.null(r) && attempt <= 3 ) {
attempt <- attempt + 1
try({
x<-2+3
prin(x)})
}
stop("The error message")
}
a <- tryCatch({
b()
}, error = function(e){
mailme(e$message)
})
Run Code Online (Sandbox Code Playgroud)
实际返回的错误信息是
Error in prin(x) : could not find function "prin"
Run Code Online (Sandbox Code Playgroud)
但是我在电子邮件中收到的错误消息是
The error message #from the stop used in function b
Run Code Online (Sandbox Code Playgroud)
如何在停靠点内调用实际的错误消息?
我有一堂课:
\nclass POI(Document):\n location = PointField(required=True)\n name = StringField(default='')\n generate_by = IntField(required=True)\n status = StringField(default='Active')\n colle\xd1\x81ted_by = IntField()\n time_created = DateTimeField(default=datetime.datetime.now)\nRun Code Online (Sandbox Code Playgroud)\n当我尝试插入时
\nPOI(location=[55.430212, 30.521000], generate_by=1241254, name="Sample", collected_by=None)\nRun Code Online (Sandbox Code Playgroud)\n发生错误
\nmongoengine.errors.FieldDoesNotExist: The fields "{'collected_by'}" do not exist on the document "POI"\nRun Code Online (Sandbox Code Playgroud)\n怎么了?
\nimg=cv2.imread(face.jpg)
predictions= DeepFace.analyze(img)
Run Code Online (Sandbox Code Playgroud)
Error: Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False.
设置enforce_detection为False会导致即使图像中没有面部,它也会读取情绪
我们如何处理这个错误,让它告诉我们没有人脸?
我对 Golang 的主要问题之一是错误处理基本上是对字符串的检查(我很乐意出错,不要犹豫:))
在下面的示例中,我尝试创建一个目录,但根据问题的类型会有不同的行为。具体来说,如果目录存在,我将直接通过。
package main
import (
"fmt"
"os"
)
func main() {
err := os.Mkdir("test", 0644)
if err != nil {
fmt.Printf("error: %v", err)
if err.Error() == "mkdir test: Cannot create a file when that file already exists" {
fmt.Printf("the dir already exists")
} else {
panic(err)
}
}
}
Run Code Online (Sandbox Code Playgroud)
它不起作用,不会记录重复的尝试。为什么?啊,糟糕,我忘记了字符串末尾的点mkdir test: Cannot create a file when that file already exists。
我觉得依赖错误字符串是脆弱的,而不是像err.ErrorType().DirectoryExists()检查这样的东西(例如有时存在net)。
我的问题:我可以在多大程度上相信错误字符串不会改变?(换句话说,mkdir test: Cannot create a file when that …
我希望块内抛出的特定错误try不被处理catch(err)
例子:
const someFunc = async () => {
...
try {
...
// This error should not be handled by the catch and go straight to the middleware
throw {
status: 404,
message: "Not Found",
};
} catch (error) {
throw {
status: 500,
message: "Something went wrong",
reason: error,
};
}
};
Run Code Online (Sandbox Code Playgroud)
之后中间件处理错误。
export const errorHandler: ErrorRequestHandler = (err, req, res, next) => {
const { status = 500, message, reason } = err;
res.status(status).json({ …Run Code Online (Sandbox Code Playgroud) !! 我是新来的!
我正在使用 datasync API 来启动任务执行,没有任何问题。我正在努力处理返回的错误结构,我想访问各个元素,但我似乎无法做到这一点。
例如,在以下错误中我希望能够访问Message_的内容
2022/03/19 09:33:48 Sync called :
InvalidRequestException: Unable to queue the task execution for task task-xxxxxxxxxxxx. The task already has another task execution exec-030b4a31dc2e33641 currently running or queued with identical Include and Exclude filter patterns. Please provide unique Include and Exclude filter patterns for the new task execution and try again.
{
RespMetadata: {
StatusCode: 400,
RequestID: "xxxxxxxxxxxxxxxxxxxxx"
},
ErrorCode: "DedupeFailed",
Message_: "Unable to queue the task execution for task task-xxxxxxxxxx. The task …Run Code Online (Sandbox Code Playgroud) 我有下面的代码需要检查是否找到任何对象的可见属性。try- except 块中的每个首字母缩略词函数如果找到则返回一个对象引用,每个都有自己的visible属性。如果未找到任何首字母缩略词对象,我的程序将因调用(例如)DR() 而引发 LookUpError。我觉得必须有一种方法来简化这段代码,这样我就不必指定所有这些单独的 try- except 块,但我无法考虑如何有效地做到这一点。
def detect_planning_workflow_page():
workflow = None
try:
if DR().visible:
workflow = "DR"
except LookupError:
pass
try:
if LL().visible:
workflow = "LL"
except LookupError:
pass
try:
if AZ().visible:
workflow = "AZ"
except LookupError:
pass
try:
if SP().visible:
workflow = "SP"
except LookupError:
pass
try:
if MS().visible:
workflow = "Define Region"
except LookupError:
pass
return workflow
Run Code Online (Sandbox Code Playgroud) 我的理解是,在现代 C++ 中,最好使用throw而不是返回错误代码。也就是说,如果我有一些功能:
void MyFunction(int foo, double bar){
// Do some stuff....
if (exception_criteria_met){
throw "Call to MyFunction with inputs" << foo << " and " << bar << " failed because ...";
}
};
Run Code Online (Sandbox Code Playgroud)
这是否意味着,为了正确处理这个问题,那么在所有调用 的函数中MyFunction,我必须实现如下所示的内容:
void MyOuterFunction(int foo){
// Do some stuff...
try {
MyFunction(foo, bar);
} catch (const char * exception_message) {
throw "Call to MyOuterFunction with inputs " << foo << " failed because call to MyFunction with ....";
};
Run Code Online (Sandbox Code Playgroud)
那么这是否意味着我必须对调用该函数调用堆栈的所有函数一直执行相同类型的错误处理? …
我在练习R语言练习时,遇到一道题,要求我访问“ eset”库中的“ genefilter”数据集;
> library(genefilter)\n> data(eset)\nRun Code Online (Sandbox Code Playgroud)\n但我总是收到以下错误;
\nIn data(eset) : data set \xe2\x80\x98eset\xe2\x80\x99 not found\nRun Code Online (Sandbox Code Playgroud)\n我遇到了同样的错误;
\n>library(globaltest);\n>data(exampleX);\n>data(exampleY);\nRun Code Online (Sandbox Code Playgroud)\n有人可以向我解释一下我在这里做错了什么吗?
\n我搜索了所有BiocManager文档,但找不到有用的答案。
一切都很好,翻译了 nextjs13.4、tailwindcss 和 i18n 中的所有内容,我没有使用打字稿,但我的图像尽管位于公共文件夹中,却无法加载到任何地方。
我在控制台中收到错误: GET http://localhost:3000/_next/image?url=%2Fimagentest.jpg&w=128&q=75 400 (错误请求)
指南:https://locize.com/blog/next-13-app-dir-i18n/
我希望你能帮助我如何修复此代码错误
error-handling ×10
python ×3
go ×2
r ×2
try-catch ×2
aws-datasync ×1
c++ ×1
deepface ×1
express ×1
javascript ×1
lookup ×1
mongodb ×1
mongoengine ×1
next.js13 ×1
nextjs-image ×1
public ×1
throw ×1
try-except ×1
typescript ×1