Catch2
if (NOT TARGET Catch2) project(Catch2 CXX) set(CMAKE_CXX_STANDARD 11) add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CU ${CMAKE_CURRENT_SOURCE_DIR}/include) # Mimic the library names in Catch2's own CMake files: add_library(Catch2::Catch2 ALIAS Catch2) # This one is historical, left over from when ApprovalTests.cpp cpp was first created. # We could encourage users to move away from it. add_library(catch2 ALIAS Catch2) endif ()0 码力 | 1 页 | 519.00 B | 5 月前3Exceptionally Bad: The Story on the Misuse of Exceptions and How to Do Better
seen in C++ • Look at original goals/ideals of exception handling • Look at the mechanics of throw/catch • Look at Exceptions in both their use and design as seen in real code • Better thinking on the me{"Pete", 21}; apply(me); } catch (const MyStatus& s) { std::cout << "error : " << s << std::endl; } ... } } Error handling Happy Path (clean) Function signature changed } catch (...) { std::cout << Exception hygiene • Throw by value • Catch by (const) reference • Rethrow using throw with no arguments • Catch handlers with derived classes placed before catch handlers with base classes Exception0 码力 | 85 页 | 2.32 MB | 5 月前3C++ Exceptions for Smaller Firmware
throw 5; } int main() { volatile int return_code = 0; try { return_code = start(); } catch (...) { return_code = -1; } return return_code; } 51Barrier #1 Exceptions disabled! 52☠ to convince you That was to show you that something is here. 94C++ Exceptions from throw to catch on GCC ARM 95Things that will NOT be covered here ● Nested exceptions ● Anything other than table based exceptions 96Consider the following 97 struct error {}; void foo() { try { bar(); } catch (error const& p_error) { // end up here... } } void bar() { destructible_t obj; baz();0 码力 | 237 页 | 6.74 MB | 5 月前3Exceptions Under the Spotlight
to throw by value, catch by const ref, and re-throw using throw.• A fail-handling mechanism void bar() { try { foo(); } catch (error_type) { // do stuff, or re-throw; } catch (…) { // do stuff, responsibility 9• A fail-handling mechanism int main() { try { bar(); } catch (error_type) { // do stuff } // don’t catch; } “Re-delegate responsibility” PART 0: WHAT ARE EXCEPTIONS 10PART I: (expensive, un-deterministic mechanism) • C++ does not return tothe throwing code (but to the catch block). Exception handlers are rare compared to function definitions. The formal usage recommendation0 码力 | 53 页 | 2.82 MB | 5 月前3Back to Basics: Exceptions
try { g(); h(); } catch( std::exception const& ex ) { /* Handle exception */ } } Three keywords throw try catch Stack unwinding Objects on the stack are try { g(); h(); } catch( std::exception const& ex ) { /* Handle exception */ } } Three keywords throw try catch Stack unwinding Objects on the stack are try { g(); h(); } catch( std::exception const& ex ) { /* Handle exception */ } } Three keywords throw try catch Stack unwinding Objects on the stack are0 码力 | 111 页 | 4.87 MB | 5 月前3The Swift Programming Language (Swift 5.7) - Apps Dissected
ways to handle errors. One way is to use do-catch. Inside the do block, you mark code that can throw an error by writing try in front of it. Inside the catch block, the error is automatically given the printerResponse = try send(job: 1040, toPrinter: "Bi Sheng") 3 print(printerResponse) 4 } catch { 5 print(error) 6 } 7 // Prints "Job sent" E X P E R I M E N T Change the printer name send(job:toPrinter:) function throws an error. You can provide multiple catch blocks that handle specific errors. You write a pattern after catch just as you do after case in a switch. PDF conversion courtesy0 码力 | 1040 页 | 10.90 MB | 1 年前3The Node.js Handbook
callback: const fs = require('fs') try { const fd = fs.openSync('/Users/joe/test.txt', 'r') } catch (err) { console.error(err) } Once you get the file descriptor, in whatever way you choose ready: const fs = require('fs') try { const stats = fs.statSync('/Users/joe/test.txt') } catch (err) { console.error(err) } The file information is included in the stats variable. What isDirectory() // false stats.isSymbolicLink() // false stats.size // 1024000 //= 1MB } catch (err) { console.log(err) } } example() 35. Node File Paths Every file in the system0 码力 | 161 页 | 1.66 MB | 1 年前3Heterogeneous Modern C++ with SYCL 2020
[=](id<1> i){ out[i] = inA[i] + inB[i]; }); }); gpuQueue.wait_and_throw(); } catch (sycl::exception &e) { /* handle SYCL exception */ } } 23 SYCL 2020 Hello WorldFirst we include [=](id<1> i){ out[i] = inA[i] + inB[i]; }); }); gpuQueue.wait_and_throw(); } catch (sycl::exception &e) { /* handle SYCL exception */ } } 24 SYCL 2020 Hello WorldIn this example [=](id<1> i){ out[i] = inA[i] + inB[i]; }); }); gpuQueue.wait_and_throw(); } catch (sycl::exception &e) { /* handle SYCL exception */ } } 25 SYCL 2020 Hello WorldIn SYCL all0 码力 | 114 页 | 7.94 MB | 5 月前3The Zig Programming Language 0.8.1 Documentation
overwritten before being used." In Debug mode, Zig writes 0xaa bytes to undefined memory. This is to catch bugs early, and to help detect use of undefined memory in a debugger. Variables A variable is a 123 a.? Optionals Equivalent to: a orelse unreachable const value: ?u3 value.? == 5678 a catch b a catch |err| b Error Unions If a is an error, returns b ("default value"), otherwise returns the unwrapped Precedence x() x[] x.y x.* x.? a!b x{} !x -x -%x ~x &x ?x * / % ** *% || + - ++ +% -% << >> & ^ | orelse catch == != < > <= >= and or = *= /= %= += -= <<= >>= &= ^= |= Arrays arrays.zig const expect = @import("std")0 码力 | 234 页 | 6.01 MB | 1 年前3Quickly Testing Qt Desktop Applications With Approval Tests
from: • Catch2, with a little bit of Qt Test • Tricks needed to use Qt with Catch2 – Useful if using different framework23 Setting up testsuite main() // Demonstrate how to create a Catch main() for #define CATCH_CONFIG_RUNNER #include <Catch.hpp> #includeint main(int argc, char* argv[]) { QApplication app(argc, argv); // -platform offscreen int result = Catch::Session() test our stuff! ☜ ☜ ☜26 ColorWidget setup – QColor object #include "catch.hpp" #include "color_widget.hpp" #include "catch_qt_string_makers.hpp" using namespace ScIDE; TEST_CASE("ColorWidget initial 0 码力 | 77 页 | 6.96 MB | 5 月前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100