首页 \ 问答 \ 导致Abort的未捕获异常(Uncaught exception that causes Abort)

导致Abort的未捕获异常(Uncaught exception that causes Abort)

我正在使用我自己的继承自std::exceptionException类。 我很确定这个课程没问题,因为它一直在努力。 我试图从构造函数中抛出一个错误:

DataBase::DataBase()
  : _result(NULL)
{
  mysql_init(&_mysql);
  mysql_options(&_mysql,MYSQL_READ_DEFAULT_GROUP,"option");
  if(!mysql_real_connect(&_mysql,"localhost","root","","keylogger",0,NULL,0))
    throw Exception(__LINE__ - 1, __FILE__, __FUNCTION__, "Can't connect to DB");
}

这是我的try / catch块:

int main(int, char **)
{
  //[...]

  Server server([...]); // DB is a private member in Server

  try
  {
    server.fdMonitor();
  }
  catch (Exception &e)
  {
    std::cout << "Error: in " << e.file() << ", " << "function " << e.function()
          << "(line " << e.line() << ") : " << std::endl
          << "\t" << e.what() << std::endl;
  }
  return (1);
}

问题是没有捕获从我的数据库构造函数抛出的异常。 这是中止消息:

 terminate called after throwing an instance of 'Exception'
     what(): Can't connect to DB
 Aborted

有任何想法吗? 提前致谢。


I'm using my own Exception class that inherits from std::exception. I'm pretty sure the class is okay since it has always worked up until now. I'm trying to throw an error from a constructor:

DataBase::DataBase()
  : _result(NULL)
{
  mysql_init(&_mysql);
  mysql_options(&_mysql,MYSQL_READ_DEFAULT_GROUP,"option");
  if(!mysql_real_connect(&_mysql,"localhost","root","","keylogger",0,NULL,0))
    throw Exception(__LINE__ - 1, __FILE__, __FUNCTION__, "Can't connect to DB");
}

Here is my try/catch block :

int main(int, char **)
{
  //[...]

  Server server([...]); // DB is a private member in Server

  try
  {
    server.fdMonitor();
  }
  catch (Exception &e)
  {
    std::cout << "Error: in " << e.file() << ", " << "function " << e.function()
          << "(line " << e.line() << ") : " << std::endl
          << "\t" << e.what() << std::endl;
  }
  return (1);
}

The problem is that the Exception thrown from my DB constructor isn't caught. Here's the abort message:

 terminate called after throwing an instance of 'Exception'
     what(): Can't connect to DB
 Aborted

Any ideas? Thanks in advance.


原文:https://stackoverflow.com/questions/26777250
更新时间:2023-04-04 13:04

最满意答案

在这种情况下,以下情况属实:

num1将等于索引的任何值,乘以它自己。 因此,当i从0开始运行时,它将在0,1,2,3和4上运行,直到它小于或等于4。

因此,num1将是:

1) 0 * 0 = 0
2) 1 * 1 = 1
3) 2 * 2 = 4
4) 3 * 3 = 9
5) 4 * 4 = 16

然后num2只计算每个的总和,即:

0 + 1 + 4 + 9 + 16 = 30

这将被分解为:

Before for loop:
num2 = 0

1) num2 = 0 + 0 = 0
2) num2 = 0 + 1 = 1
3) num2 = 1 + 4 = 5
4) num2 = 5 + 9 = 14
5) num2 = 14 + 16 = 30

它通过添加到目前为止的总数为num1来实现这一点。

希望这能澄清一点。

编辑:

正如sharonbn所提到的,var不是java中的有效类型,它应该是'int'。

此外,你有:

int num2 = 0:

在这里你以冒号结尾(:)这应该是一个分号(;)。


In this case, the following is true:

num1 will be equal to whatever the index is, multiplied by itself. Therefore this will run on 0, 1, 2, 3 and 4 as your i starts as 0 and runs until it is less than or equal to 4.

Therefore, num1 will be:

1) 0 * 0 = 0
2) 1 * 1 = 1
3) 2 * 2 = 4
4) 3 * 3 = 9
5) 4 * 4 = 16

Then num2 simply calculates the sum of each of these, which would be:

0 + 1 + 4 + 9 + 16 = 30

This would be broken up into:

Before for loop:
num2 = 0

1) num2 = 0 + 0 = 0
2) num2 = 0 + 1 = 1
3) num2 = 1 + 4 = 5
4) num2 = 5 + 9 = 14
5) num2 = 14 + 16 = 30

It does this by adding whatever num1 was to the total so far.

Hope this clarifes it a bit.

EDIT:

As sharonbn has mentioned, var is not a valid type in java, this should be 'int'.

Also, you have:

int num2 = 0:

Here you have ended with a colon (:) this should be a semi-colon (;).

相关问答

更多
  • 这是完整的工作代码,您尝试打印完全正确。 试试吧。 ArrayList> outer = new ArrayList>(); ArrayList inner ; for (int i = 1; i <= 2; i++) { inner = new ArrayList(); //each time new ArrayList
  • 默认情况下,ptraced进程会在向其发送信号时停止。 当您的孩子提出SIGTRAP时,会向父母发送SIGCHLD信号。 由于父母被追踪,它会像孩子一样停止。 僵局。 如果添加代码以使父忽略SIGCHLD,则程序按预期运行: Child is traced Child is tracing Child stopped: 5 Stopsig status 5. Child exiting... Parent exiting... A ptraced process will, by default, get ...
  • 你的函数计算: 3 ^ n 。 数字3乘以n-1个呼叫的结果。 f(n) = 3 * f(n-1) ; f(0) = 1; f(1) = 3 * f(0) = 3 * 1 = 3; f(2) = 3 * f(1) = 3 * 3 = 9; f(3) = 3 * f(2) = 3 * 3 * f(1) = 3 * 3 * 3 = 27 。 。 。 f(5) = 3 * 3 * 3 * 3 * 3 = 243 Your function computes : 3^n. The number 3 is multi ...
  • 那么你在谈论两件不同的事情。 如果您想查看寄存器的内容,您需要执行该程序,因此您需要创建一个二进制文件。 针对系统,然后单步执行。 是的,如果你有正确的gdb指向正确的系统,gdb将会工作。 您也可以使用jtag调试器,单步执行然后转储寄存器。 这些与汇编语言无关,您可能希望在单步执行时看到汇编语言级别的指令,但您需要编译为二进制文件才能运行它。 由于你的程序没有做任何事你需要小心不要优化,即使-O1优化也会删除你的代码。 这是一些尝试。 我有一个拇指指令集模拟器,拇指是ARM的16位子集(仍然在ARM系列 ...
  • 我开始这个小组是因为我对这种事感兴趣, http://groups.google.com/group/python-ray-tracing-community/web/list-of-python-statistical-ray-tracers 。 在这里,您将找到一个(非详尽的)python光线跟踪器列表,它应该指向正确的方向。 我还有一个用Python编写的光线跟踪器,它可以满足您的需求,但尚未发布! I started this group because I'm interested in this ...
  • 为什么不使用一个简单的if构造呢? var imagesPerPage = 2 if ( response.d.length > imagesPerPage ) { alert('more'); } else { alert('less'); } 在你的代码中,循环总是运行response.d.length时间。 在前两次,你的假的部分火灾,并导致两个“更多”警报。 之后,所有其他运行使用if-clause的真正部分,并返回“more”。 无论如何,无论您提醒什么,所有运行都会完成。 但是,您可 ...
  • 在Simple Injector中解析实例的速度非常快,除非您的构造函数做得太多 ,否则不应该成为问题。 尽管如此,添加跟踪是微不足道的,可以按照以下步骤完成(对于v2.8及更高版本): container.Options.RegisterResolveInterceptor((context, producer) => { var watch = Stopwatch.StartNew(); try { return producer(); ...
  • 在这种情况下,以下情况属实: num1将等于索引的任何值,乘以它自己。 因此,当i从0开始运行时,它将在0,1,2,3和4上运行,直到它小于或等于4。 因此,num1将是: 1) 0 * 0 = 0 2) 1 * 1 = 1 3) 2 * 2 = 4 4) 3 * 3 = 9 5) 4 * 4 = 16 然后num2只计算每个的总和,即: 0 + 1 + 4 + 9 + 16 = 30 这将被分解为: Before for loop: num2 = 0 1) num2 = 0 + 0 = 0 2) n ...
  • 一种选择是重写for循环,以便赋值指向临时变量并将跟踪代码插入循环体中。 例如,像这样的循环: for foo.x in range(3): print(foo.x) 可以改写为: for _temp in range(3): print('loop variable will be set to', _temp) foo.x = _temp print(foo.x) 为此,我们实现了一个NodeTransformer : class ForLoopRewriter(as ...
  • 我发现http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtrace0.htm很有用。 它不会一直回到基础,但可能仍然有帮助(提示:如果你看到像我一样破碎的字体字符,它意味着是一个点积)。 I found http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtrace0.htm useful. It doesn't go all the way back ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。