cangjie-error-handle

Implement robust error handling in Cangjie with exception hierarchies and control flow patterns.

4|1|Updated Mar 29, 2026
One-click install
npx skills add https://github.com/JunjieChen0/NJUST --skill cangjie-error-handle-junjiechen0
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cangjie-error-handle
Source: https://github.com/JunjieChen0/NJUST/tree/main/.njust-ai/skills/cangjie-error-handle
Command: npx skills add https://github.com/JunjieChen0/NJUST --skill cangjie-error-handle-junjiechen0

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a structured guide for managing exceptions and errors in the Cangjie language, including how to distinguish Error vs Exception, define custom exceptions, and implement robust error handling patterns.

Core Features & Use Cases

  • Error vs Exception: clearly separates internal system errors from logic errors and shows when to inherit from Exception but not from Error.
  • Exception API & Custom Rules: explains how to define custom exceptions using open class inheritance and the allowed rules for extending Exception.
  • Control Flow Patterns: covers try/catch/finally, try-with-resources, and various CatchPattern usage to safely handle errors.
  • Option-based Error Handling: describes using Option<T> with match, ??, ? and getOrThrow() to manage missing values safely.
  • Use Case: implement a small module that validates input, handles potential failures, and ensures resources are cleaned up.

Quick Start

Write a small Cangjie snippet that demonstrates throwing and catching a custom exception inside a try/catch block.

Frequently Asked Questions about cangjie-error-handle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle exceptions in Cangjie using try/catch/finally?

You implement error handling in Cangjie using try/catch/finally blocks and try-with-resources for cleanup. CatchPattern structures allow you to intercept specific exceptions, while finally blocks guarantee resource cleanup during application workflows.

What is the difference between Error and Exception in the Cangjie language?

In Cangjie, Error and Exception separate internal system errors from logic errors. You should inherit custom classes from Exception for application logic failures, but not from Error, which is reserved for internal system-level failures.

How do I define custom exceptions in Cangjie?

To define custom exceptions in Cangjie, you extend the open class Exception using inheritance. This approach follows the allowed rules for extending Exception, enabling you to create specific exception types tailored to your application's logic failures.

How does Option-based error handling work in Cangjie?

Option-based error handling in Cangjie uses Option<T> with match, ??, ?, and getOrThrow() to safely manage missing values. This pattern provides an alternative to exceptions for controlling flow when optional data might be absent.

Can I use try-with-resources in Cangjie to clean up resources?

Try-with-resources in Cangjie ensures automatic resource cleanup when handling exceptions. By wrapping resource initialization within this control flow pattern, you guarantee that resources are safely released even if logic errors or failures occur.