welcome to my blog
The best place on the internet for random code!
www.therealgromer.com









Archive for the ‘C#’ Category

Aug
25
    
Posted (Mike) in ASP.Net, BG Alert, C#, Coding on August-25-2007

I was getting this exception while finishing up the sign up page on BG Alert and I couldn’t figure out why it was doing it.  I was getting redirected after I was able to sign up.  I was getting my welcome email for my “new user,” but I was also getting an email about this error (the system sends me emails on any error for during this testing phase to help me fix bugs and issues).  I was even getting redirected, which is what threw me so much.  I was getting an error caused by the Response.Redirect, but it was still running.

Turns out that it was because the Response.Redirect was inside a try..catch block.  To fix this error, all you do is pull the Response.Redirect out of the try block or ignore the error.  Hope this helps some of you out!



Apr
27
    
Posted (Mike) in C#, Coding on April-27-2007

If any of you code in Visual Studio 2005, you might have seen this exception thrown before.

Loader Lock Detected

It can be really frustrating if you don’t have the answer. Let me take that stress away. All you need to do is press Ctrl + Alt + E and you will get this window:

Exceptions Window

Expand Managed Debugging Assistants and then scroll down until you see the LoaderLock checkbox. All you need to do is uncheck it.

Loader Lock Checkbox

Hit Okay and you won’t see this problem in this current project again. It will come back in other projects though. I’ve heard there are registry hacks to fix this, but I have yet to try. If anyone has, please comment on the success of it!



Apr
27
    
Posted (Mike) in C#, Coding on April-27-2007

If you are a programmer, I’m sure you have used try/catch blocks in your code to hopefully eliminate any dreadful unhandled exceptions. We all know they usually happen only when giving a presentation and that’s no good! You could go by throwing generic exceptions all day long…

  1. throw new Exception(“Hey, you broke my program :(”);

That’s a bit generic though. This is where custom exceptions come in. It’s more intuitive and much less generic than throwing Exception() every time. It will also give you better control over choosing what to do when any exception is thrown. Instead of having one catch block, you’ll have the catch blocks for your custom exceptions with the generic Exception() last to catch anything that got past.

First thing you’ll need to do is create a Windows Library project. I named mine CustomExceptions.

Create project window.

When the new project is open, you’ll have a file called Class1.cs which you can rename to the name of the exception you are going to create. When you do this, you will see a window like this:

Rename file popup.

Just click the Yes button and your class name will change throughout your project. Now we’re ready to do the actual coding. When creating custom exceptions, we must extend the ApplicationException class.

  1. public class IllegalInputException : ApplicationException
  2. {
  3. }

Now we need to create the instance variables to be used in your exception. We’ll need one for the severity level, one for the log level, one for the inner exception and one for the message.

  1. private int severityLevelOfException;
  2. private int logLevelOfException;
  3. private Exception innerException;
  4. private string customMessage;

The severity and log levels allow you to give a bit more information about the type and severity of the exception you are throwing. If your exception was caused by another exception, it will store the original exception data as the inner exception. Last, the custom message is what you put in it to be used when it is caught. Read the rest of this entry »