summaryrefslogtreecommitdiff
path: root/lib/status_handler_impl.h
blob: e1212b65bb892428a54dfd61305a8c3529ca80ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved        *
// **************************************************************************

#ifndef STATUSHANDLER_IMPL_H_INCLUDED
#define STATUSHANDLER_IMPL_H_INCLUDED

#include <zen/optional.h>
#include <zen/file_error.h>
#include "process_callback.h"

//template <typename Function> inline
//bool tryReportingError(Function cmd, ProcessCallback& handler) //return "true" on success, "false" if error was ignored
//{
//    for (;;)
//        try
//        {
//            cmd(); //throw FileError
//            return true;
//        }
//        catch (zen::FileError& error)
//        {
//            switch (handler.reportError(error.toString())) //may throw!
//            {
//                case ProcessCallback::IGNORE_ERROR:
//                    return false;
//                case ProcessCallback::RETRY:
//                    break; //continue with loop
//            }
//        }
//}


template <typename Function> inline
zen::Opt<std::wstring> tryReportingError2(Function cmd, ProcessCallback& handler) //return ignored error message if available
{
    for (;;)
        try
        {
            cmd(); //throw FileError
            return zen::NoValue();
        }
        catch (zen::FileError& error)
        {
            switch (handler.reportError(error.toString())) //may throw!
            {
                case ProcessCallback::IGNORE_ERROR:
                    return error.toString();
                case ProcessCallback::RETRY:
                    break; //continue with loop
            }
        }
}


#endif //STATUSHANDLER_IMPL_H_INCLUDED
bgstack15