---
title: "Hur gör ni med egen-definierade exceptions?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/c-cpp/155508-hur-gör-ni-med-egen-definierade-exceptions"
topic: "C/C++"
topic_url: "https://www.webforum.nu/amne/c-cpp"
author: "Compusa"
published: "2007-01-03T15:03:35.000Z"
updated: "2007-01-03T15:03:35.000Z"
replies: 0
views: 327
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/c-cpp/155508-hur-gör-ni-med-egen-definierade-exceptions"
---

# Hur gör ni med egen-definierade exceptions?

## #1 — Compusa, 2007-01-03T15:03Z

Hej,
håller på lite med felhantering i C++ och har skrivit några egen-definierade exceptions. För tillfället har jag mina exception-klasser i en enda header-fil men jag har funderat på om man ska ha en header-fil per exception-klass? Hur brukar ni göra?

Alternativ 1: **exceptions.h**

```
class FileUnavailableException : public runtime_error
{
};

class IllegalOperationException : public runtime_error
{
};
```

Alternativ 2: 
**FileUnavailableException.h**

```
class FileUnavailableException : public runtime_error
{
};
```

**IllegalOperationException.h**

```
class IllegalOperationException : public runtime_error
{
};
```

Mina exception-klasser är ju ganska "små" och det känns som det blir väldigt plottrigt att köra efter en-fil-per-klass regeln...

Permalänk: https://www.webforum.nu/p/155508

---

Tråden på webben: https://www.webforum.nu/amne/c-cpp/155508-hur-gör-ni-med-egen-definierade-exceptions
