exception
exception holds the error classes the rest of the library throws. Nothing in it depends on the Apps Script runtime.
Packages
Package | Covers |
|---|---|
| the base classes and the general-purpose exceptions |
| failures raised by the Sheets, Slides, and Admin SDK helpers |
| authentication failures |
The hierarchy, the catching patterns, and the table of which function throws which exception are in Exception handling. This page covers using the classes in your own code.
Extending the hierarchy
A script with its own failure modes can join the hierarchy rather than throwing bare Error objects. Extend RuntimeException for anything raised while the script runs:
That is the whole class. Exception sets name from new.target, so the subclass reports its own name with no constructor of its own:
It also inherits the behaviour that matters at the catch site — Exception.isException() recognises it, and instanceof RuntimeException holds.
Wrapping a caught error
Every constructor accepts an existing Error and reuses its message, which keeps the original text while changing the type:
Choosing a class
Prefer an existing class where one fits — a caller that already handles IllegalArgumentException will handle yours:
Situation | Class |
|---|---|
An argument is the wrong type or out of range |
|
A required value was |
|
A string argument was empty |
|
A credential was missing or rejected |
|
A dependency was never configured |
|
Full list
Exceptions lists every class with a link to its source.
This documentation was generated with AI (Claude) from the library's source code.