---
id: 1186
title: Exception Shielding... let's do it
slug: exception-shielding-come-on
date: '2009-03-13T04:51:35Z'
modified: '2009-03-13T04:51:35Z'
status: publish
type: post
author: pmoelgaard
categories:
  - Uncategorized
tags:
  - Best Practices
  - Code Design
excerpt: null
canonicalPath: /posts/exception-shielding-come-on
featuredImage: null
commentCount: 0
wordCount: 183
readingTimeMinutes: 1
hasMedia: true
hasVideos: false
url: 'https://forwardthinking.pemo.me/posts/exception-shielding-come-on'
---
Use the Exception Shielding pattern to sanitize unsafe exceptions by replacing them with exceptions that are safe by design. Return only those exceptions to the client that have been sanitized or exceptions that are safe by design. Exceptions that are safe by design do not contain sensitive information in the exception message, and they do not contain a detailed stack trace, either of which might reveal sensitive information about the Web service's inner workings.  
  

[![](/media/wp/2009/03/aa480591-thumbch5-excepshield-f01-en-us-msdn10.gif)](/media/wp/2009/03/aa480591ch5-excepshield-f01-en-us-msdn10.gif)For some anticipated exceptions that are safe by design, such as data validation errors, the Web service returns appropriate information to the client. For other exceptions, such as authentication failures, the exception logic sanitizes the exception, replacing it with an exception that is safe by design.

Remember, always create systems exposed to the internet based on some basic premises, such as e.g. not telling the caller of a service something revealing the implementation, but tell the caller something that only relates to the logical layer. Don't do it for security alone, but allow the (developer) client of your service to gain enough information to go on a qualified bug-hunt...
