-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
300448d
commit 25c165e
Showing
6 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ add_projects( | |
argument_exception | ||
exception_ptr | ||
system_exception | ||
user_defined_exception | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
examples/xtd.core.examples/exceptions/user_defined_exception/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(user_defined_exception) | ||
find_package(xtd REQUIRED) | ||
add_sources(README.md src/user_defined_exception.cpp) | ||
target_type(CONSOLE_APPLICATION) |
29 changes: 29 additions & 0 deletions
29
examples/xtd.core.examples/exceptions/user_defined_exception/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# user_defined_exception | ||
|
||
Shows how to use [xtd::exception](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1exception.html) exception. | ||
|
||
## Sources | ||
|
||
[src/user_defined_exception.cpp](src/user_defined_exception.cpp) | ||
|
||
[CMakeLists.txt](CMakeLists.txt) | ||
|
||
## Build and run | ||
|
||
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following: | ||
|
||
```cmake | ||
xtdc run | ||
``` | ||
|
||
## Output | ||
|
||
``` | ||
type = user_defined_exception::employee_list_not_found_exception | ||
help_link = | ||
h_result = 0x80131500 (2148734208) | ||
inner_exception = (null) | ||
message = The employee list does not exist. | ||
source = user_defined_exception | ||
stack_trace = at main [0x0000665C] in /Users/yves/Projects/xtd/examples/xtd.core.examples/exceptions/user_defined_exception/src/user_defined_exception.cpp:line 24 | ||
``` |
44 changes: 44 additions & 0 deletions
44
examples/xtd.core.examples/exceptions/user_defined_exception/src/user_defined_exception.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <xtd/console> | ||
#include <xtd/exception> | ||
|
||
using namespace xtd; | ||
using namespace xtd::diagnostics; | ||
|
||
namespace user_defined_exception { | ||
class employee_list_not_found_exception : public exception { | ||
public: | ||
employee_list_not_found_exception(const stack_frame& stack_frame = null) : exception {"The employee list does not exist."_t, stack_frame} { | ||
} | ||
|
||
employee_list_not_found_exception(const string& message, const stack_frame& stack_frame = null) : exception {message, stack_frame} { | ||
} | ||
|
||
template<typename exception_t> | ||
employee_list_not_found_exception(const string& message, const exception_t& inner, const stack_frame& stack_frame = null) : exception {message, inner, stack_frame} { | ||
} | ||
}; | ||
} | ||
|
||
auto main() -> int { | ||
try { | ||
throw user_defined_exception::employee_list_not_found_exception {csf_}; | ||
} catch(const exception& e) { | ||
console::write_line("type = {}", e.get_type()); | ||
console::write_line("help_link = {}", e.help_link()); | ||
console::write_line("h_result = 0x{0:X8} ({0})", static_cast<uint>(e.h_result())); | ||
console::write_line("inner_exception = {}", e.inner_exception()); | ||
console::write_line("message = {}", e.message()); | ||
console::write_line("source = {}", e.source()); | ||
console::write_line("stack_trace = {}", e.stack_trace()); | ||
} | ||
} | ||
|
||
// This code can produce the following output : | ||
// | ||
// type = user_defined_exception::employee_list_not_found_exception | ||
// help_link = | ||
// h_result = 0x80131500 (2148734208) | ||
// inner_exception = (null) | ||
// message = The employee list does not exist. | ||
// source = user_defined_exception | ||
// stack_trace = at main [0x0000665C] in /Users/yves/Projects/xtd/examples/xtd.core.examples/exceptions/user_defined_exception/src/user_defined_exception.cpp:line 24 |