【初心者歓迎】C/C++室 Ver.99【環境依存OK】 [無断転載禁止]©5ch.io
■ このスレッドは過去ログ倉庫に格納されています
0136デフォルトの名無しさん
2016/08/08(月) 18:59:35.32ID:TzS/bNsO125からなぜそう解釈されたのか意味がわからんのと、
my_throwの存在意義がわからんけど、
int compute(int n) throw(exception) {
int temp[n]; // bad_allocになるかも、ここでは無視する
int result = hoge(temp, n);
if (result == 0) { throw runtime_error("failed"); }
return result;
}
int caller() throw(my_exception) {
try { return compute(100000); }
catch (const bad_alloc& e) { terminate(); } // もう無理
catch (const exception& e) {
log(e.what(), __LINE__, __FILE__); // ログ残して
throw my_exception(current_exception(), __LINE__, __FILE__); // 上位に教えてあげなきゃ
}
}
突っ込みどころあると思うけど、で、例外処理っていうのは、
catchする側の処理と、throwする側の処理の両方を含むってことで、
catchする側はどんな例外をcatchして何をするとか、
throwする側はどんな例外を投げるべきなのか考えるのでは?
■ このスレッドは過去ログ倉庫に格納されています