Thomas’ Developer Blog

June 6, 2008

Forcing Server Side Error in VB.Net

Filed under: Asp.Net Framework 2.0, vb.net — sanzon @ 7:26 pm

It’s been a long time since I’ve updated. Mainly because I haven’t had anything new come up to post about and I’ve been on vacation. So today I have something new!.. for a change lol

There are times when you may want to force an error within a serverside script.

These errors will only be useful to the developer so that they are not going insane trying to figure out what is going wrong with the script.

Well I’ve been racking my brain over this one for a long time. Of course I just kind of ignored it for a while, until I came accross a script that did exactly what I wanted it to! So now I have the solution and it’s really simple.

Simply add:

Throw New Exception(“Thumbnail size must be aat least 1% of the original size”)

Where the invalid argument is.

So for example you may have:

If myvar = “” Then
     Throw New Exception(“Thumbnail size must be aat least 1% of the original size”)
End If

So there are a lot of times when this can be useful. For example if you work with strings and have to make sure the string is in the proper format. You simply use a regular expression to check to see if the string is valid. If not throw an exception  to the developer letting them now: hey! You screwed up here! Fix it!

It’s funny how these things are always so simple yet no one knows the answer, or makes it out to be 10 times more complex then it ever had to be.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: