Home » Archives for June 2016

Month: June 2016

Automatically set Azure app settings

The bigger your applications are, the more settings you’ll have in the web.config file. If you run your webapp in Azure and there are a lot of settings, then it’s annoying to set all the values manually. It would be much easier, if Azure would automatically show all app settings in the section in the azure portal and you just need to adapt them. Unfortunately there this doesn’t work out of the box and therefore the application settings will look like:
Read more

How to correctly throw Exceptions in C#

I’ve seen it many times that throwing Exceptions is done in the wrong way. That’s why I write a short blog post about Exception Handling in C# and how to do it in the right way:

There are mainly three ways of throwing an exception:

try { ... } catch (Exception ex) { throw ex; } // bad
try { ... } catch (Exception ex) { throw; } // good
try { ... } catch (Exception ex) { throw MyCustomException("message", ex); } // better

The main difference between the three ways above is, what you’ll get out of the stack trace. Let’s create a simple C# console application to see the differences:
Read more