Kind: Class
Source: packages/core/errors/exceptions/runtime.exception.ts
Part of: Core
RuntimeException represents an error that occurs during application execution and can be propagated through the core error-handling flow. It provides a what() method for retrieving a human-readable description of the failure. Use it when an operation cannot continue because of an unexpected runtime condition.
Extends: Error
Methods
| Method | Signature | Returns |
|---|---|---|
what | what() | void |
Diagram
mermaidgraph LR A[Application operation] --> B{Runtime failure?} B -- Yes --> C[RuntimeException] C --> D[what()] D --> E[Readable error description] B -- No --> F[Continue execution]
Usage
tsimport { RuntimeException } from '@your-package/core/errors/exceptions/runtime.exception';
function loadConfiguration(configPath?: string): void {
if (!configPath) {
throw new RuntimeException('Configuration path is required.');
}
// Continue loading the configuration...
}
try {
loadConfiguration();
} catch (error) {
if (error instanceof RuntimeException) {
console.error(error.what());
} else {
throw error;
}
}
AI Coding Instructions
- Throw
RuntimeExceptionfor runtime conditions that prevent an operation from completing normally. - Provide actionable, human-readable error messages when constructing the exception.
- Use
instanceof RuntimeExceptionwhen handling this specific error type. - Prefer
what()when consuming the exception description to follow the established exception API. - Avoid using this exception for expected control flow; validate inputs and return normal results where appropriate.
How it works
RuntimeException is an exported subclass of the built-in Error class. packages/core/errors/exceptions/runtime.exception.ts:1 It is also re-exported through the core exceptions barrel. packages/core/errors/exceptions/index.ts:2
- Its constructor accepts an optional
messageargument, defaulting to an empty string, and passes that value toError; consequently, the inheritedmessageis initialized from that argument.packages/core/errors/exceptions/runtime.exception.ts:2-4 what()returns the instance’s current inheritedmessageproperty.packages/core/errors/exceptions/runtime.exception.ts:6-8- The class has no code-visible input validation, custom error fields, logging, or other side effects beyond calling the
Errorconstructor.packages/core/errors/exceptions/runtime.exception.ts:1-8
In this repository, it is both a base class for more specific exceptions—including CircularDependencyException, UnknownDependenciesException, and InvalidClassException—and a directly thrown error type. packages/core/errors/exceptions/circular-dependency.exception.ts:1-3 packages/core/errors/exceptions/unknown-dependencies.exception.ts:1-6 packages/core/errors/exceptions/invalid-class.exception.ts:1-4
Direct call sites throw a message-less RuntimeException when an injector cannot find a token in its collection, when a module’s provider map lacks its metatype, or when middleware resolution cannot find an instance wrapper. packages/core/injector/injector.ts:171-174 packages/core/injector/module.ts:141-144 packages/core/middleware/middleware-module.ts:203-206
Used by
11 references from 11 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (11)
RpcDecoratorMetadata—packages/microservices/errors/invalid-grpc-message-decorator.exception.ts:3InvalidGrpcPackageDefinitionMissingPackageDefinitionException—packages/microservices/errors/invalid-grpc-package-definition-missing-package-definition.exception.ts:3InvalidGrpcPackageDefinitionMutexException—packages/microservices/errors/invalid-grpc-package-definition-mutex.exception.ts:3InvalidGrpcPackageException—packages/microservices/errors/invalid-grpc-package.exception.ts:6InvalidGrpcServiceException—packages/microservices/errors/invalid-grpc-service.exception.ts:6InvalidKafkaClientTopicException—packages/microservices/errors/invalid-kafka-client-topic.exception.ts:6InvalidMessageException—packages/microservices/errors/invalid-message.exception.ts:6InvalidProtoDefinitionException—packages/microservices/errors/invalid-proto-definition.exception.ts:6
…and 3 more.
Was this page helpful?