03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Exception H<strong>and</strong>l<strong>in</strong>g x 681<br />

<strong>VB</strong>.<strong>NET</strong><br />

mailBody = mailBody.Repalce("##Name##", Name.Text) ' Replace is misspelled<br />

Response.Write()<br />

' Required parameter<br />

' for the Write method<br />

' is miss<strong>in</strong>g<br />

If i > 10<br />

' Do someth<strong>in</strong>g here<br />

End If<br />

' Miss<strong>in</strong>g keyword Then<br />

C#<br />

mailBody = mailBody.Repalce("##Name##", Name.Text); // Replace is misspelled<br />

Response.Write();<br />

if (i > 10)<br />

// Do someth<strong>in</strong>g here<br />

}<br />

// Required parameter for the<br />

// Write method is miss<strong>in</strong>g<br />

// Miss<strong>in</strong>g open<strong>in</strong>g brace or<br />

// extraneous clos<strong>in</strong>g brace<br />

Compile errors are always displayed <strong>in</strong> the Error List (accessible through the View Í Error List<br />

menu), shown <strong>in</strong> Figure 18-1 for a C# website.<br />

FIGURE 18-1<br />

You can force the compiler to give you an up-to-date list of all the compilation errors <strong>in</strong> your site. To<br />

do this, from the ma<strong>in</strong> menu choose Build Í Build Web Site. When you want to force VS to recompile<br />

the entire site (which is slower as it also recompiles files that haven’t changed), choose Build Í<br />

Rebuild Web Site <strong>in</strong>stead.<br />

To go to the location where the error occurred so you can fix it, double-click the error <strong>in</strong> the Error<br />

List. To cycle through the errors <strong>and</strong> the code where the error occurs, click an error <strong>in</strong> the Error List<br />

<strong>and</strong> press F8 to go to the next error.<br />

Logic Errors<br />

Logic errors are often harder to f<strong>in</strong>d because they compile f<strong>in</strong>e but only happen dur<strong>in</strong>g the execution<br />

of your code. Consider the follow<strong>in</strong>g buggy example:<br />

<strong>VB</strong>.<strong>NET</strong><br />

Dim fromAddress As Str<strong>in</strong>g = "you@example.com"<br />

Dim toAddress As Str<strong>in</strong>g = EmailAddress.Text

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!