title: In DDD where to keep custom exceptions (application exceptions)? In Infrastructure layer?
body: <p>I'm building a app with following architecture:</p>
  
  <p>UI - Application - Domain - Infrastructure</p>
  
  <p>I have a Application Layer that need use custom exceptions. Where I keep these custom exceptions? In Infrastructure layer? The problem is my Application Layer don't have reference to Infrastructure layer.</p>
  
  <p>What is the correct way?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Here's my code that throw a exception in Application Layer:</p>
  
  <pre><code>public void InsertNewImage(ImagemDTO imagemDTO)
  {
      if (isValidContentType(imagemDTO.ImageStreamContentType))
      {
          string nameOfFile = String.Format("{0}{1}", Guid.NewGuid().ToString(), ContentTypeHelper.GetExtension(imagemDTO.ImageStreamContentType));
  
          string path = String.Format("{0}{1}", ImageSettings.PathToSave, nameOfFile);
  
          _fileService.SaveFile(imagemDTO.ImageStream, path);
  
          Imagem imagem = new Imagem()
                              {
                                  Titulo = imagemDTO.Titulo,
                                  Descricao = imagemDTO.Descricao,
                                  NomeArquivo = nameOfFile
                              };
  
          _imagemRepository.Add(imagem);
  
          _dbContext.SaveChanges();
      } else
      {
          throw new WrongFileTypeException(String.Format("{0} is not allowed.", ContentTypeHelper.GetExtension(imagemDTO.ImageStreamContentType)));
      }
  }
  </code></pre>
  
  <p>Even  ImageSettings is a ConfigurationSection is in my Application Layer because it uses it. I don't see other way I can transfer my ImageSettings (which should stay in Infrastrucuture Layer) to Infrastructure Layer, someone can help?</p>
  
  <pre><code>public class ImageSettings : ConfigurationSection
  {
      /// &lt;summary&gt;
      /// Caminha onde será salvo as imagens
      /// &lt;/summary&gt;
      [ConfigurationProperty("pathToSave", IsRequired = true)]
      public string PathToSave
      {
          get { return (string)this["pathToSave"]; }
          set { this["pathToSave"] = value; }
      }
  
      /// &lt;summary&gt;
      /// Extensões permitidas pra upload
      /// &lt;/summary&gt;
      [ConfigurationProperty("allowedExtensions", IsRequired = true)]
      public string AllowedExtensions
      {
          get { return (string)this["allowedExtensions"]; }
          set { this["allowedExtensions"] = value; }
      }
  
      /// &lt;summary&gt;
      /// Tamanho das imagens
      /// &lt;/summary&gt;
      [ConfigurationProperty("imageSize")]
      public ImageSizeCollection ImageSize
      {
          get
          {
              return (ImageSizeCollection)this["imageSize"];
          }
      }
  }
  </code></pre>