Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
nsExceptionService Class Reference

Exception Service definition. More...

#include <nsExceptionService.h>

Inheritance diagram for nsExceptionService:
Inheritance graph
[legend]
Collaboration diagram for nsExceptionService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIEXCEPTIONSERVICE
NS_DECL_NSIEXCEPTIONMANAGER
NS_DECL_NSIOBSERVER 
nsExceptionService ()
nsresult DoGetExceptionFromProvider (nsresult errCode, nsIException *defaultException, nsIException **_richError)
void Shutdown ()
void registerExceptionProvider (in nsIExceptionProvider provider, in PRUint32 moduleCode)
 Installs an "exception provider" which is capable of translating an nsresult into an exception.
void unregisterExceptionProvider (in nsIExceptionProvider provider, in PRUint32 moduleCode)
void setCurrentException (in nsIException error)
 Sets (or clears with nsnull) the current error on the this thread.
nsIException getCurrentException ()
 Gets the current error for the current thread, or NULL if no error.
nsIException getExceptionFromProvider (in nsresult rc, in nsIException defaultException)
 Gets an exception from a registered exception provider.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Static Public Member Functions

static void AddThread (nsExceptionManager *)
static void DropThread (nsExceptionManager *)
static void DoDropThread (nsExceptionManager *thread)
static void DropAllThreads ()
static void PR_CALLBACK ThreadDestruct (void *data)

Public Attributes

nsSupportsHashtable mProviders
readonly attribute
nsIExceptionManager 
currentExceptionManager
 Obtains an exception manager for the current thread.

Static Public Attributes

static nsExceptionManagerfirstThread = nsnull
static PRLocklock = nsnull
static PRUintn tlsIndex = BAD_TLS_INDEX

Private Member Functions

 ~nsExceptionService ()

Detailed Description

Exception Service definition.

Definition at line 52 of file nsExceptionService.h.


Constructor & Destructor Documentation

Definition at line 154 of file nsExceptionService.cpp.

  : mProviders(4, PR_TRUE) /* small, thread-safe hashtable */
{
#ifdef NS_DEBUG
  if (PR_AtomicIncrement(&totalInstances)!=1) {
    NS_ERROR("The nsExceptionService is a singleton!");
  }
#endif
  /* member initializers and constructor code */
  if (tlsIndex == BAD_TLS_INDEX) {
    PRStatus status;
    status = PR_NewThreadPrivateIndex( &tlsIndex, ThreadDestruct );
    NS_WARN_IF_FALSE(status==0, "ScriptErrorService could not allocate TLS storage.");
  }
  lock = PR_NewLock();
  NS_WARN_IF_FALSE(lock, "Error allocating ExceptionService lock");

  // observe XPCOM shutdown.
  nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
  NS_WARN_IF_FALSE(observerService, "Could not get observer service!");
  if (observerService)
    observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}

Here is the call graph for this function:

Definition at line 178 of file nsExceptionService.cpp.

{
  Shutdown();
  /* destructor code */
#ifdef NS_DEBUG
  PR_AtomicDecrement(&totalInstances);
#endif
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 318 of file nsExceptionService.cpp.

{
    PR_Lock(lock);
    thread->mNextThread = firstThread;
    firstThread = thread;
    NS_ADDREF(thread);
    PR_Unlock(lock);
}

Here is the call graph for this function:

Definition at line 327 of file nsExceptionService.cpp.

{
    nsExceptionManager **emp = &firstThread;
    while (*emp != thread) {
        NS_ABORT_IF_FALSE(*emp, "Could not find the thread to drop!");
        emp = &(*emp)->mNextThread;
    }
    *emp = thread->mNextThread;
    NS_RELEASE(thread);
}

Here is the caller graph for this function:

nsresult nsExceptionService::DoGetExceptionFromProvider ( nsresult  errCode,
nsIException defaultException,
nsIException **  _richError 
)

Definition at line 290 of file nsExceptionService.cpp.

{
    // Check for an existing exception
    nsresult nr = GetCurrentException(_exc);
    if (NS_SUCCEEDED(nr) && *_exc) {
        (*_exc)->GetResult(&nr);
        // If it matches our result then use it
        if (nr == errCode)
            return NS_OK;
        NS_RELEASE(*_exc);
    }
    nsProviderKey key(NS_ERROR_GET_MODULE(errCode));
    nsCOMPtr<nsIExceptionProvider> provider =
        dont_AddRef((nsIExceptionProvider *)mProviders.Get(&key));

    // No provider so we'll return the default exception
    if (!provider) {
        *_exc = defaultException;
        NS_IF_ADDREF(*_exc);
        return NS_OK;
    }

    return provider->GetException(errCode, defaultException, _exc);
}

Here is the call graph for this function:

Definition at line 345 of file nsExceptionService.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 338 of file nsExceptionService.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Gets the current error for the current thread, or NULL if no error.

Gets an exception from a registered exception provider.

This has no effect on the "current exception"

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Installs an "exception provider" which is capable of translating an nsresult into an exception.

This enables error providers to return simple nsresults and only provide rich errors when specifically requested. It also has the advantage of allowing code like the DOM to handle all errors in a single function rather than at each XPCOM entry point. NOTE: This interface must be thread-safe - it will be called on whatever thread needs the error translation performed.

Sets (or clears with nsnull) the current error on the this thread.

Definition at line 198 of file nsExceptionService.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 188 of file nsExceptionService.cpp.

{
  if (!lock) {
    NS_WARNING("nsExceptionService ignoring thread destruction after shutdown");
    return;
  }
  DropThread( (nsExceptionManager *)data );
}

Here is the call graph for this function:


Member Data Documentation

Obtains an exception manager for the current thread.

Definition at line 76 of file nsIExceptionService.idl.

Definition at line 75 of file nsExceptionService.h.

Definition at line 81 of file nsExceptionService.h.

nsSupportsHashtable nsExceptionService::mProviders

Definition at line 77 of file nsExceptionService.h.

Definition at line 83 of file nsExceptionService.h.


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