![]() |
#2
yuccn2013-03-23 10:38
|
00131168 jmp _CxxThrowException (1325D6h)
反汇编调试的时候碰到的??
我调试的是一个try块,想要了解try,throw,catch这三个之间的关系??程序内部是周末运行的?
它们有什么格式??
是不是
try{不确定的代码}
catch{捕捉错误信息}
throw又是什么时候用,又运用在哪里??
我调试的代码也顺便贴出

#include <iostream>
#include <climits>
unsigned long returnFactorial(unsigned short num) throw (const char *);
int main()
{
unsigned short num = 0;
std::cout << "请输入一个整数: ";
while( !(std::cin>>num) || (num<1) )
{
std::cin.clear(); // 清除状态
std::cin.ignore(100, '\n'); // 清除缓冲区
std::cout << "请输入一个整数:";
}
std::cin.ignore(100, '\n');
try
{
unsigned long factorial = returnFactorial(num);
std::cout << num << "的阶乘值是: " << factorial;
}
catch(const char *e)
{
std::cout << e;
}
return 0;
}
unsigned long returnFactorial(unsigned short num) throw (const char *)
{
unsigned long sum = 1;
unsigned long max = ULONG_MAX;
for( int i=1; i <= num; i++ )
{
sum *= i;
max /= i;
}
if( max < 1 )
{
throw "悲催。。。该基数太大,无法在该计算机计算求出阶乘值。\n";
}
else
{
return sum;
}
}
#include <climits>
unsigned long returnFactorial(unsigned short num) throw (const char *);
int main()
{
unsigned short num = 0;
std::cout << "请输入一个整数: ";
while( !(std::cin>>num) || (num<1) )
{
std::cin.clear(); // 清除状态
std::cin.ignore(100, '\n'); // 清除缓冲区
std::cout << "请输入一个整数:";
}
std::cin.ignore(100, '\n');
try
{
unsigned long factorial = returnFactorial(num);
std::cout << num << "的阶乘值是: " << factorial;
}
catch(const char *e)
{
std::cout << e;
}
return 0;
}
unsigned long returnFactorial(unsigned short num) throw (const char *)
{
unsigned long sum = 1;
unsigned long max = ULONG_MAX;
for( int i=1; i <= num; i++ )
{
sum *= i;
max /= i;
}
if( max < 1 )
{
throw "悲催。。。该基数太大,无法在该计算机计算求出阶乘值。\n";
}
else
{
return sum;
}
}