top of page
Search

DAT BLOG POST 12

  • daniel-ewers2
  • Jun 21, 2021
  • 2 min read

Sessions 18-19 – EXCEPTIONS


What Have I Learned?

This week I learned about exceptions/exception handling. As stated by TutorialsPoint (n.d.), “An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.”


Here is an example of implementing exception handling into my project:


As you can see, I have implemented a try and catch handler. This will try to perform the tasks that are encapsulated within the curly brackets. If it completes the task correctly, it will return the new data table. If it throws an error at any point, a dialog box will display with the error message string, then close the connection and return. In doing this, we can see what the error is that is occurring when the code runs. Rather than having the _conn.Close() method being called, I can also implement a “finally” to close the connection.



Why Have I Learned This?

I believe that I have learned this as exceptions are very useful to help us troubleshoot our code. We can also use exceptions to perform other tasks in scenarios where we might want to do so. C# provides us with an easy to use structure for handling these exceptions, therefor I believe that it was a very useful and important skill to acquire.



How Have I Learned This?

I have learned this by doing some research into what exceptions are and how I implement exception handling into my code. I performed a series of tests using stored procedures from my game and calling them from the Windows form application. I purposely made errors to see if it was picking up on them correctly. I got the results I expected and was satisfied.


Tutorialspoint. (n.d.). C# - Exception Handling - Tutorialspoint. Retrieved June 21, 2021, from https://www.tutorialspoint.com/csharp/csharp_exception_handling.htm

 
 
 

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2021 by Dwewers2021 ~ Blog. Proudly created with Wix.com

bottom of page