![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
checked-exceptions
Advanced tools
A utility library to create and manage checked exceptions in typescript
A utility library to create and manage checked exceptions in typescript.
npm:
npm i checked-exceptions --save
yarn:
yarn add checked-exceptions
A checked exception can be created by just importing check
function for the library and passing it the type
of the exception.
import {check} from 'checked-exceptions'
const NotImplemented = check('NotImplemented')
throw new NotImplemented()
Once a checked exception class has been created, an instance of the checked exception can be created using the new
operator or using the static of()
function, for eg:
Using the new operator
const err = new NotImplemented()
Using the of function
const err = NotImplemented.of()
A custom exception with additional meta data can be created by passing a second argument for eg:
type User = {id: number; name: string}
const UserIdNotFound = check(
'UserIdNotFound',
(user: User) => `Could not find user with id: ${user.id}`
)
throw new UserIdNotFound({id: 1900, name: 'Foo'})
The second argument is of type function
and is used to generate the message string when the exception is thrown.
The default properties of an exception such as stack
and message
work like they do in a typical Error
object. Additional properties such as data
, type
is also added, for eg:
type User = {id: number; name: string}
const UserIdNotFound = check(
'UserIdNotFound',
(user: User) => `Could not find user with id: ${user.id}`
)
const err = new UserIdNotFound({id: 1900, name: 'Foo'})
console.log(err.data.id) // prints 1900
console.log(err.type) // prints 'UserIdNotFound'
To access the type of the exception you can use the info
property on the created checked exception —
type User = {id: number; name: string}
const UserIdNotFound = check(
'UserIdNotFound',
(user: User) => `Could not find user with id: ${user.id}`
)
type UserIdNodeFoundException = typeof UserIdNotFound.info
const err: UserIdNodeFoundException = new UserIdNotFound({
id: 1900,
name: 'Foo'
})
FAQs
A utility library to create and manage checked exceptions in typescript
We found that checked-exceptions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.