# Error Handling Guide

Handle parsing errors gracefully.

## Throw Errors (Default)

```javascript { .api }
import { marked } from "marked";

try {
  const html = marked.parse(malformedMarkdown);
} catch (err) {
  console.error('Parse error:', err.message);
}
```

## Silent Mode

```javascript { .api }
import { marked } from "marked";

marked.setOptions({ silent: true });
const html = marked.parse(malformedMarkdown);
// Returns: <p>An error occurred:</p><pre>Error message</pre>
```

## Error Recovery

```javascript { .api }
import { marked } from "marked";

function safeParse(markdown, options = {}) {
  try {
    return {
      success: true,
      html: marked.parse(markdown, { ...options, silent: false }),
      error: null
    };
  } catch (err) {
    return {
      success: false,
      html: marked.parse(markdown, { ...options, silent: true }),
      error: err.message
    };
  }
}
```

## Common Error Scenarios

- Invalid input type (null/undefined)
- Malformed tokens (low-level API)
- Extension errors
- Async errors

See [Troubleshooting Guide](./troubleshooting.md) for specific issues.
