src: Move exception handling code to one function
This commit is contained in:
parent
11cb4ea214
commit
eff3dfd50b
|
@ -456,14 +456,5 @@ int main(int argc, char **argv) {
|
|||
} // namespace nghttp2
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
return nghttp2::main(argc, argv);
|
||||
} catch (std::bad_alloc &) {
|
||||
fputs("Out of memory\n", stderr);
|
||||
} catch (std::exception &x) {
|
||||
fputs("Exception caught: ", stderr);
|
||||
fputs(x.what(), stderr);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
return nghttp2::run_app(nghttp2::main, argc, argv);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ extern "C" {
|
|||
#include "comp_helper.h"
|
||||
}
|
||||
|
||||
#include "template.h"
|
||||
|
||||
namespace nghttp2 {
|
||||
|
||||
typedef struct { int dump_header_table; } inflate_config;
|
||||
|
@ -281,14 +283,5 @@ int main(int argc, char **argv) {
|
|||
} // namespace nghttp2
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
return nghttp2::main(argc, argv);
|
||||
} catch (std::bad_alloc &) {
|
||||
fputs("Out of memory\n", stderr);
|
||||
} catch (std::exception &x) {
|
||||
fputs("Exception caught: ", stderr);
|
||||
fputs(x.what(), stderr);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
return nghttp2::run_app(nghttp2::main, argc, argv);
|
||||
}
|
||||
|
|
|
@ -2714,14 +2714,5 @@ int main(int argc, char **argv) {
|
|||
} // namespace nghttp2
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
return nghttp2::main(argc, argv);
|
||||
} catch (std::bad_alloc &) {
|
||||
fputs("Out of memory\n", stderr);
|
||||
} catch (std::exception &x) {
|
||||
fputs("Exception caught: ", stderr);
|
||||
fputs(x.what(), stderr);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
return nghttp2::run_app(nghttp2::main, argc, argv);
|
||||
}
|
||||
|
|
|
@ -384,14 +384,5 @@ int main(int argc, char **argv) {
|
|||
} // namespace nghttp2
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
return nghttp2::main(argc, argv);
|
||||
} catch (std::bad_alloc &) {
|
||||
fputs("Out of memory\n", stderr);
|
||||
} catch (std::exception &x) {
|
||||
fputs("Exception caught: ", stderr);
|
||||
fputs(x.what(), stderr);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
return nghttp2::run_app(nghttp2::main, argc, argv);
|
||||
}
|
||||
|
|
13
src/shrpx.cc
13
src/shrpx.cc
|
@ -2551,15 +2551,4 @@ int main(int argc, char **argv) {
|
|||
|
||||
} // namespace shrpx
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
return shrpx::main(argc, argv);
|
||||
} catch (std::bad_alloc &) {
|
||||
fputs("Out of memory\n", stderr);
|
||||
} catch (std::exception &x) {
|
||||
fputs("Exception caught: ", stderr);
|
||||
fputs(x.what(), stderr);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int main(int argc, char **argv) { return run_app(shrpx::main, argc, argv); }
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "nghttp2_config.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
|
@ -196,6 +198,22 @@ inline std::unique_ptr<char[]> strcopy(const std::unique_ptr<char[]> &val) {
|
|||
return strcopy(val.get());
|
||||
}
|
||||
|
||||
inline int run_app(std::function<int(int, char **)> app, int argc,
|
||||
char **argv) {
|
||||
try {
|
||||
return app(argc, argv);
|
||||
} catch (const std::bad_alloc &) {
|
||||
fputs("Out of memory\n", stderr);
|
||||
} catch (const std::exception &x) {
|
||||
fputs("Exception caught: ", stderr);
|
||||
fputs(x.what(), stderr);
|
||||
fputs("\n", stderr);
|
||||
} catch (...) {
|
||||
fputs("Custom exception caught\n", stderr);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
} // namespace nghttp2
|
||||
|
||||
#endif // TEMPLATE_H
|
||||
|
|
Loading…
Reference in New Issue