docstream.h
docstring.h
environment.h
+ ExceptionMessage.h
filefilterlist.h
filename.h
filetools.h
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/convert.h"
+#include "support/ExceptionMessage.h"
#include "support/os.h"
#include "support/package.h"
#include "support/path.h"
// we need to parse for "-dbg" and "-help"
easyParse(argc, argv);
- support::init_package(to_utf8(from_local8bit(argv[0])),
+ try { support::init_package(to_utf8(from_local8bit(argv[0])),
cl_system_support, cl_user_support,
support::top_build_dir_is_one_level_up);
+ } catch (support::ExceptionMessage const & message) {
+ if (message.type_ == support::ErrorException) {
+ Alert::error(message.title_, message.details_);
+ exit(1);
+ } else if (message.type_ == support::WarningException) {
+ Alert::warning(message.title_, message.details_);
+ }
+ }
if (!use_gui) {
// FIXME: create a ConsoleApplication
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file ExceptionMessage.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * A store of the paths to the various different directoies used
+ * by LyX. These paths differ markedly from one OS to another,
+ * following the local Windows, MacOS X or Posix conventions.
+ */
+#ifndef LYX_MESSAGE_H
+#define LYX_MESSAGE_H
+
+#include "support/docstring.h"
+
+#include <exception>
+
+namespace lyx {
+namespace support {
+
+
+enum ExceptionType {
+ ErrorException,
+ WarningException
+};
+
+
+class ExceptionMessage: public std::exception {
+public:
+ ExceptionMessage(ExceptionType type, docstring const & title,
+ docstring const & details)
+ : exception((to_utf8(title) + "\n" + to_utf8(details)).c_str()),
+ type_(type), title_(title), details_(details) {}
+
+ virtual ~ExceptionMessage() {}
+
+ ExceptionType type_;
+ docstring title_;
+ docstring details_;
+};
+
+} // namespace support
+} // namespace lyx
+
+#endif // LYX_MESSAGE_H
docstring.h \
environment.h \
environment.C \
+ ExceptionMessage.h \
filefilterlist.C \
filefilterlist.h \
filename.C \
#include "support/os_win32.h"
#include "support/lstrings.h"
#include "support/filetools.h"
+#include "support/ExceptionMessage.h"
#include "support/package.h"
#include "support/path.h"
#include "debug.h"
+#include "gettext.h"
#include <boost/assert.hpp>
}
-namespace {
-
-void bail_out()
-{
-#ifndef CXX_GLOBAL_CSTD
- using std::exit;
-#endif
- exit(1);
-}
-
-} // namespace anon
-
-
GetFolderPath::GetFolderPath()
: folder_module_(0),
folder_path_func_(0)
{
folder_module_ = LoadLibrary("shfolder.dll");
if (!folder_module_) {
- lyxerr << "Unable to load shfolder.dll\nPlease install."
- << std::endl;
- bail_out();
+ throw ExceptionMessage(ErrorException, _("System file not found"),
+ _("Unable to load shfolder.dll\nPlease install."));
}
folder_path_func_ = reinterpret_cast<function_pointer>(::GetProcAddress(folder_module_, "SHGetFolderPathA"));
if (folder_path_func_ == 0) {
- lyxerr << "Unable to find SHGetFolderPathA in shfolder.dll\n"
- "Don't know how to proceed. Sorry."
- << std::endl;
- bail_out();
+ throw ExceptionMessage(ErrorException, _("System function not found"),
+ _("Unable to find SHGetFolderPathA in shfolder.dll\n"
+ "Don't know how to proceed. Sorry."));
}
}
#include "support/environment.h"
#include "support/filetools.h"
#include "support/lstrings.h"
+#include "support/ExceptionMessage.h"
#include "support/os.h"
#if defined (USE_WINDOWS_PACKAGING)
}
-void bail_out()
-{
-#ifndef CXX_GLOBAL_CSTD
- using std::exit;
-#endif
- exit(1);
-}
-
-
// Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
string const abs_path_from_command_line(string const & command_line)
{
string const abs_binary = get_binary_path(exe);
if (abs_binary.empty()) {
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Unable to determine the path to the "
- "LyX binary from the command line %1$s"),
- lyx::from_utf8(exe)))
- << std::endl;
- bail_out();
+ throw ExceptionMessage(ErrorException,
+ _("LyX binary not found"),
+ bformat(_("Unable to determine the path to the LyX binary from the command line %1$s"),
+ lyx::from_utf8(exe)));
}
return abs_binary;
}
}
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Unable to determine the system directory "
+ throw ExceptionMessage(ErrorException, _("No system directory"),
+ bformat(_("Unable to determine the system directory "
"having searched\n"
"\t%1$s\n"
"Use the '-sysdir' command line parameter or "
"set the environment variable LYX_DIR_15x to "
"the LyX system directory containing the file "
"`chkconfig.ltx'."),
- lyx::from_utf8(searched_dirs_str)))
- << std::endl;
+ lyx::from_utf8(searched_dirs_str)));
- bail_out();
// Keep the compiler happy.
return string();
}
FileName const abs_path = fileSearch(dir, file);
if (abs_path.empty()) {
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s switch.\n"
- "Directory %2$s does not contain %3$s."),
- lyx::from_utf8(command_line_switch), lyx::from_utf8(dir),
- lyx::from_utf8(file)))
- << std::endl;
+ throw ExceptionMessage(WarningException, _("File not found"), bformat(
+ _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
+ lyx::from_utf8(command_line_switch), lyx::from_utf8(dir),
+ lyx::from_utf8(file)));
}
return !abs_path.empty();
FileName const abs_path = fileSearch(dir, file);
if (abs_path.empty()) {
// FIXME UNICODE
- lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s environment variable.\n"
- "Directory %2$s does not contain %3$s."),
- lyx::from_utf8(env_var), lyx::from_utf8(dir), lyx::from_utf8(file)))
- << std::endl;
+ throw ExceptionMessage(WarningException, _("File not found"), bformat(
+ _("Invalid %1$s environment variable.\n"
+ "Directory %2$s does not contain %3$s."),
+ lyx::from_utf8(env_var), lyx::from_utf8(dir),
+ lyx::from_utf8(file)));
}
return !abs_path.empty();
docstring const fmt =
_("Invalid %1$s environment variable.\n%2$s is not a directory.");
- lyxerr << lyx::to_utf8(bformat(fmt, lyx::from_utf8(env_var), lyx::from_utf8(dir)))
- << std::endl;
+ throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
+ fmt, lyx::from_utf8(env_var), lyx::from_utf8(dir)));
}
return success;
#include "support/fs_extras.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
+#include "support/ExceptionMessage.h"
#include "support/os.h"
#include "support/package.h"
#include "support/unicode.h"
}
lyx::support::os::init(argc, argv);
- support::init_package(to_utf8(from_local8bit(argv[0])),
+
+ try { support::init_package(to_utf8(from_local8bit(argv[0])),
cl_system_support, cl_user_support,
support::top_build_dir_is_two_levels_up);
+ } catch (support::ExceptionMessage const & message) {
+ cerr << to_utf8(message.title_) << ':\n'
+ << to_utf8(message.details_) << endl;
+ if (message.type_ == support::ErrorException)
+ exit(1);
+ }
// Now every known option is parsed. Look for input and output
// file name (the latter is optional).