find-exception-issues

Detects exception handling issues in PHP code. Finds swallowed exceptions, generic catches, missing exception handling, re-throwing without context, exception in finally.

59 stars

Best use case

find-exception-issues is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Detects exception handling issues in PHP code. Finds swallowed exceptions, generic catches, missing exception handling, re-throwing without context, exception in finally.

Teams using find-exception-issues should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/find-exception-issues/SKILL.md --create-dirs "https://raw.githubusercontent.com/dykyi-roman/awesome-claude-code/main/skills/find-exception-issues/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/find-exception-issues/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How find-exception-issues Compares

Feature / Agentfind-exception-issuesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Detects exception handling issues in PHP code. Finds swallowed exceptions, generic catches, missing exception handling, re-throwing without context, exception in finally.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Exception Issue Detection

Analyze PHP code for exception handling problems.

## Detection Patterns

### 1. Swallowed Exceptions (Empty Catch)

```php
// BUG: Exception completely ignored
try {
    $this->riskyOperation();
} catch (Exception $e) {
    // Empty catch block - bug hidden
}

// BUG: Only logging, no handling
try {
    $this->process();
} catch (Exception $e) {
    $this->logger->error($e->getMessage());
    // No re-throw, no return, execution continues
}
```

### 2. Generic Exception Catching

```php
// BUG: Catches everything
try {
    $this->save();
} catch (Exception $e) {
    // Catches TypeError, LogicException, etc.
}

// BUG: Using Throwable carelessly
try {
    $this->process();
} catch (Throwable $t) {
    // Catches Error too, hiding fatal issues
}
```

### 3. Missing Exception Handling

```php
// BUG: Unchecked external call
$response = $httpClient->request('GET', $url); // May throw

// BUG: File operations without try
$content = file_get_contents($path); // Returns false on failure

// BUG: JSON without error check
$data = json_decode($json); // May return null on error
```

### 4. Re-throwing Without Context

```php
// BUG: Lost context
try {
    $this->process();
} catch (DatabaseException $e) {
    throw new RuntimeException('Failed'); // Lost original exception
}

// FIXED: Preserve chain
throw new RuntimeException('Failed to process', 0, $e);
```

### 5. Exception in Finally Block

```php
// BUG: Exception in finally hides original
try {
    $this->process();
} finally {
    $this->cleanup(); // If this throws, original exception is lost
}

// FIXED:
} finally {
    try {
        $this->cleanup();
    } catch (Exception $e) {
        $this->logger->warning('Cleanup failed', ['exception' => $e]);
    }
}
```

### 6. Catch Order Issues

```php
// BUG: Parent before child
try {
    $this->process();
} catch (Exception $e) {
    // Catches everything
} catch (InvalidArgumentException $e) {
    // Never reached
}
```

### 7. Return in Finally

```php
// BUG: Return in finally overrides exception
try {
    throw new Exception('Error');
} finally {
    return true; // Exception is suppressed
}
```

### 8. Using Exception for Control Flow

```php
// BUG: Exception as goto
try {
    foreach ($items as $item) {
        if ($found) {
            throw new FoundException($item);
        }
    }
} catch (FoundException $e) {
    $result = $e->getItem();
}
```

### 9. Missing @throws Documentation

```php
// BUG: Undocumented exception
public function process(): void
{
    if (!$valid) {
        throw new InvalidArgumentException(); // Not documented
    }
}
```

## Grep Patterns

```bash
# Empty catch blocks
Grep: "catch\s*\([^)]+\)\s*\{\s*\}" --glob "**/*.php"

# Generic Exception catch
Grep: "catch\s*\(\s*(Exception|\\\\Exception)\s+" --glob "**/*.php"

# Throwable catch
Grep: "catch\s*\(\s*(Throwable|\\\\Throwable)\s+" --glob "**/*.php"

# throw new without previous
Grep: "throw new \w+Exception\([^,)]+\);" --glob "**/*.php"

# Return in finally
Grep: "finally\s*\{[^}]*return" --glob "**/*.php"
```

## Severity Classification

| Pattern | Severity |
|---------|----------|
| Swallowed exception | 🔴 Critical |
| Return in finally | 🔴 Critical |
| Generic Throwable catch | 🟠 Major |
| Lost exception chain | 🟠 Major |
| Exception for control flow | 🟡 Minor |
| Missing @throws | 🟡 Minor |

## Best Practices

### Specific Exception Handling

```php
try {
    $this->save();
} catch (UniqueConstraintException $e) {
    throw new DuplicateEmailException($email, 0, $e);
} catch (ConnectionException $e) {
    throw new DatabaseUnavailableException(0, $e);
}
// Let other exceptions bubble up
```

### Proper Exception Chain

```php
throw new DomainException(
    sprintf('Failed to process order %s', $orderId),
    previous: $originalException
);
```

### Safe Finally

```php
try {
    $this->process();
} finally {
    try {
        $this->cleanup();
    } catch (Throwable $e) {
        // Log but don't throw
        $this->logger->error('Cleanup failed', ['exception' => $e]);
    }
}
```

## Output Format

```markdown
### Exception Issue: [Description]

**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Swallowed|Generic Catch|Missing Chain|...]

**Issue:**
[Description of the exception handling problem]

**Code:**
```php
// Problematic code
```

**Fix:**
```php
// Proper exception handling
```
```

Related Skills

find-type-issues

59
from dykyi-roman/awesome-claude-code

Detects type issues in PHP code. Finds implicit type coercion, mixed types in comparisons, unsafe casting, type mismatches in returns.

find-resource-leaks

59
from dykyi-roman/awesome-claude-code

Detects resource leaks in PHP code. Finds unclosed file handles, database connections not released, streams not freed, missing finally blocks, temporary files not cleaned.

find-race-conditions

59
from dykyi-roman/awesome-claude-code

Detects race conditions in PHP code. Finds shared mutable state, check-then-act patterns, TOCTOU vulnerabilities, concurrent modification issues.

find-null-pointer-issues

59
from dykyi-roman/awesome-claude-code

Detects null pointer issues in PHP code. Finds property/method access on null, missing null checks, nullable returns without handling, optional chaining gaps.

find-logic-errors

59
from dykyi-roman/awesome-claude-code

Detects logic errors in PHP code. Finds incorrect conditions, wrong operators, missing switch cases, inverted logic, short-circuit evaluation issues.

find-infinite-loops

59
from dykyi-roman/awesome-claude-code

Detects infinite loop risks in PHP code. Finds missing break conditions, incorrect loop variables, unbounded recursion, circular references.

find-boundary-issues

59
from dykyi-roman/awesome-claude-code

Detects boundary issues in PHP code. Finds array index out of bounds, empty collection access, off-by-one errors, integer overflow, string length issues.

bug-root-cause-finder

59
from dykyi-roman/awesome-claude-code

Root cause analysis methods for PHP bugs. Provides 5 Whys technique, fault tree analysis, git bisect guidance, and stack trace parsing.

yii-knowledge

59
from dykyi-roman/awesome-claude-code

Yii framework knowledge base. Provides Yii3 modular architecture, DDD integration, PSR-7/PSR-15 compliance, persistence, DI, security (RBAC, auth), event system (PSR-14), queue/jobs, infrastructure components (cache, rate limiter, HTTP client), testing, and antipatterns for Yii PHP projects.

troubleshooting-template

59
from dykyi-roman/awesome-claude-code

Generates troubleshooting guides and FAQ sections for PHP projects. Creates problem-solution documentation.

trace-request-lifecycle

59
from dykyi-roman/awesome-claude-code

Traces full request lifecycle from Router through Middleware, Controller, UseCase, Repository to Response. Documents HTTP methods, routes, middleware stack, response codes, and error handling paths.

trace-data-transformation

59
from dykyi-roman/awesome-claude-code

Maps data transformation chains — Request DTO to Command to Entity to Response DTO. Identifies mappers, serializers, type conversions, and data loss points across layer boundaries.