master
h 79 lines 1.52 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 Exceptions.h
8
9 Abstract:
10
11 Header file for Exceptions.
12
13 --*/
14 #pragma once
15
16 #include "Argument.h"
17
18 #include <string>
19 #include <string_view>
20 #include <utility>
21 #include <vector>
22
23 namespace wsl::windows::wslc {
24 struct CLIException
25 {
26 CLIException(std::wstring_view message) : m_message(message)
27 {
28 }
29
30 const std::wstring& Message() const
31 {
32 return m_message;
33 }
34
35 protected:
36 std::wstring m_message;
37 };
38
39 // Specific exception for command parsing errors
40 struct CommandException : CLIException
41 {
42 CommandException(std::wstring_view message) : CLIException(message)
43 {
44 }
45 };
46
47 // Specific exception for argument parsing errors
48 struct ArgumentException : CommandException
49 {
50 ArgumentException(std::wstring_view message) : CommandException(message)
51 {
52 }
53
54 ArgumentException(std::wstring_view message, Argument argument) : CommandException(message), m_arguments{std::move(argument)}
55 {
56 }
57
58 ArgumentException(std::wstring_view message, std::vector<Argument> arguments) :
59 CommandException(message), m_arguments(std::move(arguments))
60 {
61 }
62
63 const std::vector<Argument>& Arguments() const
64 {
65 return m_arguments;
66 }
67
68 private:
69 std::vector<Argument> m_arguments;
70 };
71
72 // Specific exception for failures after command and argument validation
73 struct ExecutionException : CLIException
74 {
75 ExecutionException(std::wstring_view message) : CLIException(message)
76 {
77 }
78 };
79 } // namespace wsl::windows::wslc