Exceptions: Difference between revisions

1,096 bytes added ,  31 January 2008
ns_succeeded
(ooms)
(ns_succeeded)
Line 6: Line 6:


* Remove all current OOM handling code
* Remove all current OOM handling code
* Rewrite call sites that use NS_SUCCEEDED


* Rewrite call sites that ignore nsresults
* Rewrite call sites that ignore nsresults
* Rewrite call sites that use NS_SUCCEEDED


These steps are explained in more detail below. And by the way, we'd love to have community help with any of these.  
These steps are explained in more detail below. And by the way, we'd love to have community help with any of these.  
Line 60: Line 60:


the if statement would be deleted.
the if statement would be deleted.
= Removing NS_SUCCEEDED =
== Background ==
Many call sites check nsresults with NS_SUCCEEDED. For example:
    nsresult rv = p->PrepareToUse();
    if (NS_SUCCEEDED(rv)) {
      p->Use();
    }
    return rv;
This doesn't make sense with exceptions, because with exceptions enabled, if PrepareToUse returns, then it succeeded.
== Investigating NS_SUCCEEDED ==
We want to rewrite call sites that use NS_SUCCEEDED to look more like something that will work with exceptions. But it's not clear yet exactly what that looks like. The first step is to analyze some existing uses of NS_SUCCEEDED to get an idea of what patterns exist and how to rewrite them. The example above, with exceptions can look like:
    p->PrepareToUse();
    p->Use();
Before we have exceptions, we will probably want something like:
    nsresult rv = p->PrepareToUse();
    if (NS_FAILED(rv)) return rv;
    p->Use();
    return NS_OK;
This would be fairly easy to rewrite to the exceptions version, because the NS_FAILED check is easily identified as equivalent to letting the exception propagate to the caller.


== Benefits of Exceptions ==
== Benefits of Exceptions ==
313

edits