我收到此错误,但我不知道如何修复它.
我正在使用Visual Studio 2013.我制作了解决方案名称MyProjectTest 这是我的测试解决方案的结构:

- function.h
#ifndef MY_FUNCTION_H
#define MY_FUNCTION_H
int multiple(int x, int y);
#endif
Run Code Online (Sandbox Code Playgroud)
-function.cpp
#include "function.h"
int multiple(int x, int y){
return x*y;
}
Run Code Online (Sandbox Code Playgroud)
- main.cpp
#include <iostream>
#include <cstdlib>
#include "function.h"
using namespace std;
int main(){
int a, b;
cin >> a >> b;
cout << multiple(a, b) << endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我是初学者; 这是一个简单的程序,它运行没有错误.我在互联网上阅读并对单元测试感兴趣,所以我创建了一个测试项目:
文件>新建>项目...>已安装>模板> Visual C++>测试>本机单元测试项目>
名称:UnitTest1 解决方案:添加到解决方案 然后位置自动切换到当前打开解决方案的路径这是解决方案的文件夹结构:

我只编辑了文件unittest1.cpp:
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../MyProjectTest/function.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; …Run Code Online (Sandbox Code Playgroud) 为了添加一些基本的错误处理,我想重写一段使用jQuery的$ .getJSON来从Flickr中提取一些照片的代码.这样做的原因是$ .getJSON不提供错误处理或使用超时.
因为$ .getJSON只是$ .ajax的包装,所以我决定改写这个东西并惊喜,它完美无缺.
现在开始有趣了.当我故意导致404(通过更改URL)或导致网络超时(没有连接到互联网)时,错误事件根本不会触发.我不知道自己做错了什么.非常感谢帮助.
这是代码:
$(document).ready(function(){
// var jsonFeed = "http://api.flickr.com/services/feeds/photos_public.gne"; // correct URL
var jsonFeed = "http://api.flickr.com/services/feeds/photos_public.gne_______"; // this should throw a 404
$.ajax({
url: jsonFeed,
data: { "lang" : "en-us",
"format" : "json",
"tags" : "sunset"
},
dataType: "jsonp",
jsonp: "jsoncallback",
timeout: 5000,
success: function(data, status){
$.each(data.items, function(i,item){
$("<img>").attr("src", (item.media.m).replace("_m.","_s."))
.attr("alt", item.title)
.appendTo("ul#flickr")
.wrap("<li><a href=\"" + item.link + "\"></a></li>");
if (i == 9) return false;
});
},
error: function(XHR, textStatus, errorThrown){
alert("ERREUR: " + textStatus); …Run Code Online (Sandbox Code Playgroud) 这个问题实际上是不久前在programming.reddit.com 上进行有趣讨论的结果.它基本归结为以下代码:
int foo(int bar)
{
int return_value = 0;
if (!do_something( bar )) {
goto error_1;
}
if (!init_stuff( bar )) {
goto error_2;
}
if (!prepare_stuff( bar )) {
goto error_3;
}
return_value = do_the_thing( bar );
error_3:
cleanup_3();
error_2:
cleanup_2();
error_1:
cleanup_1();
return return_value;
}
Run Code Online (Sandbox Code Playgroud)
goto这里的使用似乎是最好的方法,导致所有可能性中最干净,最有效的代码,或者至少在我看来.在Code Complete中引用Steve McConnell :
goto在分配资源,对这些资源执行操作,然后释放资源的例程中很有用.使用goto,您可以清理代码的一部分.goto可以降低忘记在检测到错误的每个位置释放资源的可能性.
此方法的另一个支持来自本节中的" Linux设备驱动程序"一书.
你怎么看?这种情况goto在C中是否有效?您是否更喜欢其他方法,这些方法会产生更复杂和/或效率更低的代码,但是要避免goto?
Google的Go语言作为一种设计选择没有例外,Linux的Linus称之为例外废话.为什么?
我有以下代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "HEAD";
request.Credentials = MyCredentialCache;
try
{
request.GetResponse();
}
catch
{
}
Run Code Online (Sandbox Code Playgroud)
如何捕获特定的404错误?WebExceptionStatus.ProtocolError只能检测到发生了错误,但未提供错误的确切代码.
例如:
catch (WebException ex)
{
if (ex.Status != WebExceptionStatus.ProtocolError)
{
throw ex;
}
}
Run Code Online (Sandbox Code Playgroud)
只是没用得多......协议异常可能是401,503,403,真的是什么.
.net c# error-handling exception-handling http-status-code-404
我有以下两种操作方法(简化问题):
[HttpGet]
public ActionResult Create(string uniqueUri)
{
// get some stuff based on uniqueuri, set in ViewData.
return View();
}
[HttpPost]
public ActionResult Create(Review review)
{
// validate review
if (validatedOk)
{
return RedirectToAction("Details", new { postId = review.PostId});
}
else
{
ModelState.AddModelError("ReviewErrors", "some error occured");
return RedirectToAction("Create", new { uniqueUri = Request.RequestContext.RouteData.Values["uniqueUri"]});
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果验证通过,我将重定向到另一页(确认).
如果发生错误,我需要显示包含错误的同一页面.
如果我这样做return View(),则会显示错误,但如果我这样做return RedirectToAction(如上所述),则会丢失模型错误.
我对这个问题并不感到惊讶,只是想知道你们是怎么处理这个问题的?
我当然可以返回相同的View而不是重定向,但我在"Create"方法中有逻辑,它填充了视图数据,我必须复制它.
有什么建议?
error-handling asp.net-mvc redirecttoaction modelstate http-redirect
没有:
如何使用FormatMessage()获取错误文本HRESULT?
HRESULT hresult = application.CreateInstance("Excel.Application");
if (FAILED(hresult))
{
// what should i put here to obtain a human-readable
// description of the error?
exit (hresult);
}
Run Code Online (Sandbox Code Playgroud) 我想在Bash脚本中引发错误,消息"Test cases Failed !!!".在Bash中如何做到这一点?
例如:
if [ condition ]; then
raise error "Test cases failed !!!"
fi
Run Code Online (Sandbox Code Playgroud) 我注意到在使用故事板时在iOS 9上运行我的应用程序时,控制台中出现以下错误.我正在使用xCode7.这是我需要关注的吗?
-[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] ** unhandled action -> <FBSSceneSnapshotAction: 0x176bfb20> {
handler = remote;
info = <BSSettings: 0x176a5d90> {
(1) = 5;
};
}
Run Code Online (Sandbox Code Playgroud) error-handling uistoryboard transition-coordinator ios9 xcode7
我已经在Apple引用的示例代码中看到了如何处理Core Data错误.即:
NSError *error = nil;
if (![context save:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, …Run Code Online (Sandbox Code Playgroud)