v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8::TryCatch Class Reference

#include <v8-exception.h>

Collaboration diagram for v8::TryCatch:

Public Member Functions

 TryCatch (Isolate *isolate)
 
 ~TryCatch ()
 
bool HasCaught () const
 
bool CanContinue () const
 
bool HasTerminated () const
 
Local< ValueReThrow ()
 
Local< ValueException () const
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueStackTrace (Local< Context > context) const
 
Local< v8::MessageMessage () const
 
void Reset ()
 
void SetVerbose (bool value)
 
bool IsVerbose () const
 
void SetCaptureMessage (bool value)
 
 TryCatch (const TryCatch &)=delete
 
void operator= (const TryCatch &)=delete
 

Static Public Member Functions

static V8_WARN_UNUSED_RESULT MaybeLocal< ValueStackTrace (Local< Context > context, Local< Value > exception)
 

Private Member Functions

void * operator new (size_t size)
 
void * operator new[] (size_t size)
 
void operator delete (void *, size_t)
 
void operator delete[] (void *, size_t)
 
internal::Address JSStackComparableAddressPrivate ()
 
void ResetInternal ()
 

Private Attributes

internal::Isolatei_isolate_
 
TryCatchnext_
 
void * exception_
 
void * message_obj_
 
internal::Address js_stack_comparable_address_
 
bool is_verbose_: 1
 
bool can_continue_: 1
 
bool capture_message_: 1
 
bool rethrow_: 1
 

Friends

class internal::Isolate
 
class internal::ThreadLocalTop
 

Detailed Description

An external exception handler.

Definition at line 138 of file v8-exception.h.

Constructor & Destructor Documentation

◆ TryCatch() [1/2]

v8::TryCatch::TryCatch ( v8::Isolate * v8_isolate)
explicit

Creates a new try/catch block and registers it with v8. Note that all TryCatch blocks should be stack allocated because the memory location itself is compared against JavaScript try/catch blocks.

Definition at line 2730 of file api.cc.

Here is the call graph for this function:

◆ ~TryCatch()

v8::TryCatch::~TryCatch ( )

Unregisters and deletes this try/catch block.

Definition at line 2752 of file api.cc.

◆ TryCatch() [2/2]

v8::TryCatch::TryCatch ( const TryCatch & )
delete

Member Function Documentation

◆ CanContinue()

bool v8::TryCatch::CanContinue ( ) const

For certain types of exceptions, it makes no sense to continue execution.

If CanContinue returns false, the correct action is to perform any C++ cleanup needed and then return. If CanContinue returns false and HasTerminated returns true, it is possible to call CancelTerminateExecution in order to continue calling into the engine.

Definition at line 2785 of file api.cc.

Here is the caller graph for this function:

◆ Exception()

v8::Local< Value > v8::TryCatch::Exception ( ) const

Returns the exception caught by this try/catch block. If no exception has been caught an empty handle is returned.

Definition at line 2798 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasCaught()

bool v8::TryCatch::HasCaught ( ) const

Returns true if an exception has been caught by this try/catch block.

Definition at line 2781 of file api.cc.

Here is the caller graph for this function:

◆ HasTerminated()

bool v8::TryCatch::HasTerminated ( ) const

Returns true if an exception has been caught due to script execution being terminated.

There is no JavaScript representation of an execution termination exception. Such exceptions are thrown when the TerminateExecution methods are called to terminate a long-running script.

If such an exception has been thrown, HasTerminated will return true, indicating that it is possible to call CancelTerminateExecution in order to continue calling into the engine.

Definition at line 2787 of file api.cc.

Here is the caller graph for this function:

◆ IsVerbose()

bool v8::TryCatch::IsVerbose ( ) const

Returns true if verbosity is enabled.

Definition at line 2858 of file api.cc.

◆ JSStackComparableAddressPrivate()

internal::Address v8::TryCatch::JSStackComparableAddressPrivate ( )
inlineprivate

There are cases when the raw address of C++ TryCatch object cannot be used for comparisons with addresses into the JS stack. The cases are: 1) ARM, ARM64 and MIPS simulators which have separate JS stack. 2) Address sanitizer allocates local C++ object in the heap when UseAfterReturn mode is enabled. This method returns address that can be used for comparisons with addresses into the JS stack. When neither simulator nor ASAN's UseAfterReturn is enabled, then the address returned will be the address of the C++ try catch handler itself.

Definition at line 273 of file v8-exception.h.

Here is the caller graph for this function:

◆ Message()

v8::Local< v8::Message > v8::TryCatch::Message ( ) const

Returns the message associated with this exception. If there is no message associated an empty handle is returned.

Definition at line 2829 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator delete()

void v8::TryCatch::operator delete ( void * ,
size_t  )
private

Definition at line 2778 of file api.cc.

Here is the call graph for this function:

◆ operator delete[]()

void v8::TryCatch::operator delete[] ( void * ,
size_t  )
private

Definition at line 2779 of file api.cc.

Here is the call graph for this function:

◆ operator new()

void * v8::TryCatch::operator new ( size_t size)
private

Definition at line 2776 of file api.cc.

Here is the call graph for this function:

◆ operator new[]()

void * v8::TryCatch::operator new[] ( size_t size)
private

Definition at line 2777 of file api.cc.

Here is the call graph for this function:

◆ operator=()

void v8::TryCatch::operator= ( const TryCatch & )
delete

◆ Reset()

void v8::TryCatch::Reset ( )

Clears any exceptions that may have been caught by this try/catch block. After this method has been called, HasCaught() will return false. Cancels the scheduled exception if it is caught and ReThrow() is not called before.

It is not necessary to clear a try/catch block before using it again; if another exception is thrown the previously caught exception will just be overwritten. However, it is often a good idea since it makes it easier to determine which operation threw a given exception.

Definition at line 2839 of file api.cc.

Here is the caller graph for this function:

◆ ResetInternal()

void v8::TryCatch::ResetInternal ( )
private

Definition at line 2850 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReThrow()

v8::Local< v8::Value > v8::TryCatch::ReThrow ( )

Throws the exception caught by this TryCatch in a way that avoids it being caught again by this same TryCatch. As with ThrowException it is illegal to execute any JavaScript operations after calling ReThrow; the caller must return immediately to where the exception is caught.

Definition at line 2792 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCaptureMessage()

void v8::TryCatch::SetCaptureMessage ( bool value)

Set whether or not this TryCatch should capture a Message object which holds source information about where the exception occurred. True by default.

Definition at line 2860 of file api.cc.

Here is the caller graph for this function:

◆ SetVerbose()

void v8::TryCatch::SetVerbose ( bool value)

Set verbosity of the external exception handler.

By default, exceptions that are caught by an external exception handler are not reported. Call SetVerbose with true on an external exception handler to have exceptions caught by the handler reported as if they were not caught.

Definition at line 2856 of file api.cc.

Here is the caller graph for this function:

◆ StackTrace() [1/2]

MaybeLocal< Value > v8::TryCatch::StackTrace ( Local< Context > context) const

Returns the .stack property of the thrown object. If no .stack property is present or if this try/catch block has not caught an exception, an empty handle is returned.

Definition at line 2824 of file api.cc.

◆ StackTrace() [2/2]

MaybeLocal< Value > v8::TryCatch::StackTrace ( Local< Context > context,
Local< Value > exception )
static

Returns the .stack property of an object. If no .stack property is present an empty handle is returned.

Definition at line 2806 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ internal::Isolate

friend class internal::Isolate
friend

Definition at line 289 of file v8-exception.h.

◆ internal::ThreadLocalTop

friend class internal::ThreadLocalTop
friend

Definition at line 290 of file v8-exception.h.

Member Data Documentation

◆ can_continue_

bool v8::TryCatch::can_continue_
private

Definition at line 285 of file v8-exception.h.

◆ capture_message_

bool v8::TryCatch::capture_message_
private

Definition at line 286 of file v8-exception.h.

◆ exception_

void* v8::TryCatch::exception_
private

Definition at line 281 of file v8-exception.h.

◆ i_isolate_

internal::Isolate* v8::TryCatch::i_isolate_
private

Definition at line 279 of file v8-exception.h.

◆ is_verbose_

bool v8::TryCatch::is_verbose_
private

Definition at line 284 of file v8-exception.h.

◆ js_stack_comparable_address_

internal::Address v8::TryCatch::js_stack_comparable_address_
private

Definition at line 283 of file v8-exception.h.

◆ message_obj_

void* v8::TryCatch::message_obj_
private

Definition at line 282 of file v8-exception.h.

◆ next_

TryCatch* v8::TryCatch::next_
private

Definition at line 280 of file v8-exception.h.

◆ rethrow_

bool v8::TryCatch::rethrow_
private

Definition at line 287 of file v8-exception.h.


The documentation for this class was generated from the following files: