diff --git a/examples/server/server.cpp b/examples/server/server.cpp index fc6d90848f099..7249095450070 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -3039,13 +3039,25 @@ int main(int argc, char ** argv) { log_data["api_key"] = "api_key: " + std::to_string(sparams.api_keys.size()) + " keys loaded"; } - // load the model - if (!ctx_server.load_model(params)) { - state.store(SERVER_STATE_ERROR); - return 1; - } else { + try { + // Attempt to load the model + if (!ctx_server.load_model(params)) { + LOG_ERROR("unable to load model", {{"error", "Load model failed"}}); + state.store(SERVER_STATE_ERROR); + return 1; + } + // Initialize the server context if the model is loaded successfully ctx_server.init(); state.store(SERVER_STATE_READY); + + } catch (const std::exception &e) { + // Catch known standard exceptions + LOG_ERROR("unable to load model", {{"error", e.what()}}); + exit(1); + } catch (...) { + // Catch all other exceptions + LOG_ERROR("unable to load model", {{"error", "Unknown Exception"}}); + return 1; } LOG_INFO("model loaded", {});