关于C++ try和catch的一个问题

maailin99 2012-01-06 08:26:19
下面是程序中得一段代码:

try
{
rgb[0] = *((BYTE*)(m_MemAddr) + (y * width + x) * bits/8);
rgb[1] = *((BYTE*)(m_MemAddr) + (y * width + x) * bits/8 + 1);
rgb[2] = *((BYTE*)(m_MemAddr) + (y * width + x) * bits/8 + 2);
}
catch ( ... )
{
SetDlgItemText( IDC_EDIT_INFO2, "Invalid position" );
return;
}

这里面try和catch是表达个什么意思呢?
还有catch后的括号内三个点省略号是什么意思?
BYTE那里的两个星号又是什么意思?

还有,那位大侠能不能告诉我为什么rgb表达式会是那个样子呢?(这里,y,x是像素坐标,bits是图像的比特值。)

问题比较多哈,还请各位大侠多多指教啊!
...全文
281 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
卡卡_苏米 2012-01-06
  • 打赏
  • 举报
回复
try
{
rgb[0] = *((BYTE*)(m_MemAddr) + (y * width + x) * bits/8);
rgb[1] = *((BYTE*)(m_MemAddr) + (y * width + x) * bits/8 + 1);
rgb[2] = *((BYTE*)(m_MemAddr) + (y * width + x) * bits/8 + 2);
}
catch ( ... )
{
SetDlgItemText( IDC_EDIT_INFO2, "Invalid position" );
return;
}

try表示 看{}里面的代码是否会抛出异常(也就是出现一些错误)
之后若有异常抛出就会进入catch进行处理,catch(...)表示抓取所有的异常,
ZSP95 2012-01-06
  • 打赏
  • 举报
回复
COLORREF RGB(
BYTE bRed, // red component of color
BYTE bGreen, // green component of color
BYTE bBlue // blue component of color
);

RGB三原色 你上边的那三个计算式 就是算出三色的各自的值 具体的 你的自己一个个研究了 你的变量代表什么有没有说明

try catch 这个是C++里的基本知识 如果try里的代码抛出异常,就会进catch里的处理代码

catch的三个点 表示捕获所有异常 BYTE后的*表示BYTE类型的指针 前面的*表示取指针内容 .
一叶之舟 2012-01-06
  • 打赏
  • 举报
回复
try
{

}//表示其中的代码有发生异常的可能。
catch//表示发生异常时跳到这块的代码
{
}
(...)表示所有异常
帅得不敢出门 2012-01-06
  • 打赏
  • 举报
回复

try {
// code that could throw an exception
}
[ catch (exception-declaration) {
// code that executes when exception-declaration is thrown
// in the try block
}
[catch (exception-declaration) {
// code that handles another exception type
} ] . . . ]
// The following syntax shows a throw expression:
throw [expression]

. If the exception-declaration statement is an ellipsis (...), the catch clause handles any type of exception, including C exceptions and system- or application-generated exceptions such as memory protection, divide by zero, and floating-point violations

具体还是看文档好了。
gykgod 2012-01-06
  • 打赏
  • 举报
回复
异常保护

要是try里的代码抛出异常,就会进catch处理 catch的三个点 表示捕获所有异常 BYTE后的*表示BYTE类型的指针 前面的*表示取指针内容

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧