Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -1,4 +1,15 @@
|
|||
struct MyException
|
||||
{
|
||||
// data with info about exception
|
||||
};
|
||||
try {
|
||||
std::string input = get_input();
|
||||
if (input.empty() )
|
||||
throw const std::string{"no input received");
|
||||
// process input ...
|
||||
|
||||
if ( result == -1) throw BAD_VALUE;
|
||||
|
||||
}
|
||||
catch (const std::string &s) {
|
||||
std::cerr << "ERROR:\t" << s << "\n";
|
||||
}
|
||||
catch (const int &e) {
|
||||
std::cerr << "ERROR:\t" << err_to_string(e) << "\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include <exception>
|
||||
struct MyException: std::exception
|
||||
struct MyException
|
||||
{
|
||||
virtual const char* what() const noexcept { return "description"; }
|
||||
}
|
||||
// data with info about exception
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
void foo()
|
||||
#include <exception>
|
||||
struct MyException: std::exception
|
||||
{
|
||||
throw MyException();
|
||||
virtual const char* what() const noexcept { return "description"; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,4 @@
|
|||
try {
|
||||
foo();
|
||||
}
|
||||
catch (MyException &exc)
|
||||
void foo()
|
||||
{
|
||||
// handle exceptions of type MyException and derived
|
||||
}
|
||||
catch (std::exception &exc)
|
||||
{
|
||||
// handle exceptions derived from std::exception, which were not handled by above catches
|
||||
// e.g.
|
||||
std::cerr << exc.what() << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// handle any type of exception not handled by above catches
|
||||
throw MyException();
|
||||
}
|
||||
|
|
|
|||
17
Task/Exceptions/C++/exceptions-5.cpp
Normal file
17
Task/Exceptions/C++/exceptions-5.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
try {
|
||||
foo();
|
||||
}
|
||||
catch (MyException &exc)
|
||||
{
|
||||
// handle exceptions of type MyException and derived
|
||||
}
|
||||
catch (std::exception &exc)
|
||||
{
|
||||
// handle exceptions derived from std::exception, which were not handled by above catches
|
||||
// e.g.
|
||||
std::cerr << exc.what() << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// handle any type of exception not handled by above catches
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@ end
|
|||
|
||||
-- 'status' is false if 'throw_error' threw an error
|
||||
-- otherwise, when everything went well, it will be true.
|
||||
-- 'errmsg' contains the error message, plus filename and line number of where the error occured
|
||||
status, errmsg = pcall(throw_error)
|
||||
-- 'errmsg' contains the error message, plus filename
|
||||
-- and line number of where the error occurred
|
||||
|
||||
local status, errmsg = pcall(throw_error)
|
||||
print("errmsg = ", errmsg)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
function throw_error_with_argment(argument)
|
||||
error(string.format("Whoops! argument = %s", argument))
|
||||
function throw_error_with_arg(arg)
|
||||
error(string.format("Whoops! argument = %s", arg))
|
||||
-- won't ever appear, due to previous error() call
|
||||
return "hello!"
|
||||
end
|
||||
|
||||
status, errmsg = pcall(throw_error_with_argment, "foobar 123")
|
||||
print("errmsg = ", errmsg)
|
||||
local status, errmsg = pcall(throw_error_with_arg, "foobar 123")
|
||||
if (status ~= 0) then
|
||||
print("errmsg = ", errmsg)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
function throw_error_with_argment(argument)
|
||||
function throw_error_with_arg(arg)
|
||||
return "hello!"
|
||||
end
|
||||
|
||||
status, errmsg = pcall(throw_error_with_argment, "foobar 123")
|
||||
print("errmsg = ", errmsg)
|
||||
local status, result = pcall(throw_error_with_arg, "foobar 123")
|
||||
if (status ~= 0)
|
||||
print("function returned ", result, ", but had errors.")
|
||||
else
|
||||
print("result = ", result)
|
||||
end
|
||||
|
|
|
|||
0
Task/Exceptions/Phix/exceptions-3.phix
Normal file
0
Task/Exceptions/Phix/exceptions-3.phix
Normal file
26
Task/Exceptions/Tcl/exceptions-2.tcl
Normal file
26
Task/Exceptions/Tcl/exceptions-2.tcl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
set f "non-existent-file.txt"
|
||||
|
||||
try {
|
||||
puts "try begin"
|
||||
|
||||
set fd [open $f "r" ]
|
||||
|
||||
set contents [read $fd]
|
||||
|
||||
puts "try end"
|
||||
|
||||
} on error { results options } {
|
||||
puts stderr "results: $results"
|
||||
|
||||
foreach {opt val} $options {
|
||||
puts stderr "options:\t$opt $val"
|
||||
|
||||
}
|
||||
}
|
||||
puts "after try block"
|
||||
|
||||
if {[info exists contents] } {
|
||||
puts "$contents"
|
||||
} else {
|
||||
puts stderr "no contents read"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue