npm.io
1.2.30 • Published 4 weeks ago

@rightcapital/exceptions

Licence
MIT
Version
1.2.30
Deps
0
Size
31 kB
Vulns
0
Weekly
0
Stars
11

exceptions

Introduction

This library provides a set of standard Exceptions

It is inspired by the PHP's SPL exceptions

Installation

pnpm add @rightcapital/exceptions

Usage

import { RuntimeException, LogicException } from '@rightcapital/exceptions';

const logicException = new LogicException('A logic exception');

try {
  // Something
  throw new RuntimeException('Crash!', logicException);
} catch (exception) {
  if (exception instanceof RuntimeException) {
    //.... BlaBlaBla
    if (exception.isCausedBy(logicException)) {
      console.log(
        'Catch you!',
        exception.name,
        ', You are caused by',
        exception.cause.name,
      );
    }
  }
}

API Reference

Here is the API documentation for the modules included in the package.