异常处理 demo2 P301 编译失败 P301 todo
//
// Created by 刘彪 on 2020/3/4.
//异常处理 demo2 P301 编译失败 P301 todo
#include <iostream>
#include <math.h>
using namespace std;
const int N=5;
int f(int) throw(int);
static int a[] = {12,32,9,34,7};
int main(){
try{
cout<<"a[1]="<<f(1)<<endl;
cout<<"a[10]="<<f(10)<<endl;
cout<<"a[3]="<<f(3)<<endl;
}catch (int){
cout<<"数组下标超界."<<endl;
}
return 0;
}
int f(int i){
if(i>=N) throw i;
return a[i];
} 
查看5道真题和解析