class ExceptionCatcher

Defined at line 43 of file ../../zircon/system/ulib/test-exceptions/include/lib/test-exceptions/exception-catcher.h

Test utility to catch and handle exceptions

The simplest usage is to allow the constructor and destructor to start and

stop. This will assert-fail if anything went wrong (e.g. an unexpected

exception was found) which is fine for most tests:

{

ExceptionCatcher catcher(process);

...

}

If you want to be able to explicitly check for failure or avoid asserts,

the ExceptionCatcher can be started and stopped manually instead, it

just involves a bit of extra boilerplate:

ExceptionCatcher catcher;

ASSERT_OK(catcher.Start(process);

...

ASSERT_OK(catcher.Stop());

This class is thread-unsafe so external locking must be applied if it is

used across threads.

Public Methods

void ExceptionCatcher ()

Defined at line 45 of file ../../zircon/system/ulib/test-exceptions/include/lib/test-exceptions/exception-catcher.h

template <typename T>
void ExceptionCatcher (const zx::task<T> & task)

Calls Start() automatically and asserts that it succeeded.

Defined at line 94 of file ../../zircon/system/ulib/test-exceptions/include/lib/test-exceptions/exception-catcher.h

void ~ExceptionCatcher ()

Calls Stop() automatically and asserts that it succeeded.

Defined at line 37 of file ../../zircon/system/ulib/test-exceptions/exception-catcher.cc

template <typename T>
zx_status_t Start (const zx::task<T> & task)

Starts watching for exceptions on |task|. Can only be bound to a single

task at a time.

Defined at line 101 of file ../../zircon/system/ulib/test-exceptions/include/lib/test-exceptions/exception-catcher.h

zx_status_t Stop ()

Stops watching for exceptions. Returns ZX_ERR_CANCELED if we got any

exceptions that were not handled via ExpectException().

Any unhandled exceptions will be closed with TRY_NEXT.

Defined at line 44 of file ../../zircon/system/ulib/test-exceptions/exception-catcher.cc

zx::result<zx::exception> ExpectException ()

Blocks until an exception is received. It then returns the exception. This will

return an error if the task exits without throwing an exception.

Defined at line 63 of file ../../zircon/system/ulib/test-exceptions/exception-catcher.cc

zx::result<zx::exception> ExpectException (const zx::thread & thread)

Same as ExpectException() but only matches exceptions on |thread|.

Any non-|thread| exceptions received will be held until they are

handled or the catcher is stopped.

Defined at line 68 of file ../../zircon/system/ulib/test-exceptions/exception-catcher.cc

zx::result<zx::exception> ExpectException (const zx::process & process)

Same as ExpectException() but only matches exceptions on |process|.

Any non-|process| exceptions received will be held until they are

handled or the catcher is stopped.

Defined at line 78 of file ../../zircon/system/ulib/test-exceptions/exception-catcher.cc