{"id":69920,"date":"2021-08-22T04:10:05","date_gmt":"2021-08-22T08:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/basics-of-exception-handling-in-net-19\/"},"modified":"2021-08-22T04:10:05","modified_gmt":"2021-08-22T08:10:05","slug":"basics-of-exception-handling-in-net-19","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=69920","title":{"rendered":"Basics of Exception Handling in .Net #19"},"content":{"rendered":"<p>Basics of Exception Handling in .Net<\/p>\n<p>Why exception handling? In your applications, unexpected error situations may occur that are out of your appication scope and your application logic. These are actually external to your application. For example, while you are reading a file from hard drive, the file may not be there; or the remote server may be too busy or unavailable to get back to you with the result of your query. Exception handling addresses such situations.<\/p>\n<p>How can you handle such situations:<\/p>\n<ul>\n<li> Use try, catch, finally structure to address such situations   <\/li>\n<li> Put the code where, you are anticipating an exception inside a try{} block. Put the code to handle the error situation in catch (Exception ex) {} blocks. You can have multiple catch blocks where each one will address a specific type of exception situation. <\/li>\n<li> One more note, the code block where exception may occur may need to execute some logic\/code whether an exception occurs or or not such as closing a file, closing the database connection. To accomplish this, you can use a finally block. A finally block is always executed, regardless of whether an exception is thrown or not.<\/li>\n<li> When an exception occurs, the events are thrown by the environment. You need to address that if you want to. Else, your users will see the errors and will cause a bad user experience.<\/li>\n<li> You can even throw exceptions on your own in your code. But why? say if you anticipate that there will be some error situations that are not external but related to your application logic and you actually do not want to handle those situations (serve some services in those situations for example) in your application. You can just throw exceptions and think that these are the conditions; you do not want to support in your application. Throw exception and provide some generalized response to your visitors.<\/li>\n<li> You can also handle exceptions throw the web objects&#8217; built in error events such as Page_Error, Global_Error, Application_Error.<\/li>\n<li> In certain situations, You can take advantage of the error pages of the webserver to provide useful information to your visitors. You can replace the default error pages of your web-server and provide customized error pages to your visitor<\/li>\n<li> Finally, you can use tracing to log the error events. Monitor the tracing to understand which types of situations occur more frequently than others. And find out a solution and apply the solution<\/li>\n<li> It is possible to turn on and off this tracing without modifying the application code. You can make use of the web.config file configurations<\/li>\n<\/ul>\n<p>Regarding error pages, you can provide your custom error pages for the standard HTTP error codes. Some codes are given below:204:No Content, 301:Moved, Moved Permanently, 302: Found, Redirect, 400:bad request, 401:unauthorized, 403: forbidden, 404:not found, 408:request time out, 500:internal server error, 503:service unavailable, 505:Http version not supported.<\/p>\n<p>You can also make use of the errorPage attribute of the Page object to define an error page for the exceptions of that particular page. Page level settings override the application level settings (as provided by web.config file)<\/p>\n<ul>\n<li> How to enable application level tracing: use something similar as below in your web.config file\n<pre style=\"padding:20px\">{ and } are used instead of  respectively. {configuration}         {system.web}            {trace enabled=\"true\" requestLimit=\"40\" localOnly=\"false\"\/}         {\/system.web}   {\/configuration}<\/pre>\n<\/li>\n<li> to enable tracing for a particular page, use the trace property of the Document object<\/li>\n<li> how to write tracing information to the trace log: Trace.Warn()<\/li>\n<\/ul>\n<p>From: http:\/\/sitestree.com\/?p=5335<br \/> Categories:19<br \/>Tags:<br \/> Post Data:2012-06-07 19:04:36<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Basics of Exception Handling in .Net Why exception handling? In your applications, unexpected error situations may occur that are out of your appication scope and your application logic. These are actually external to your application. For example, while you are reading a file from hard drive, the file may not be there; or the remote &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=69920\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-69920","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":70311,"url":"http:\/\/bangla.sitestree.com\/?p=70311","url_meta":{"origin":69920,"position":0},"title":"Basic Information on Exception Handling in .Net #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"September 1, 2021","format":false,"excerpt":"Brought from our old site: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1356&title=Basics%20of%20Exception%20Handling%20in%20.Net Basic Information on Exception Handling in .Net Why exception handling? In your applications, unexpected error situations may occur that are out of your application scope and your application logic. These are actually external to your application. For example, while you are reading a file\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":76061,"url":"http:\/\/bangla.sitestree.com\/?p=76061","url_meta":{"origin":69920,"position":1},"title":"Oracle: Error management and exception handling in PL\/SQL","author":"Sayed","date":"May 13, 2024","format":false,"excerpt":"Raise Error in Oracle RAISE VALUE_ERROR; Raise Application Error in Oracle Create custom exception and raise it. Handle Exception You could also insert into error log table and RAISE Reference: https:\/\/blogs.oracle.com\/connect\/post\/error-management","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2024\/05\/image-34.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":9897,"url":"http:\/\/bangla.sitestree.com\/?p=9897","url_meta":{"origin":69920,"position":2},"title":"PHP Exception Handling","author":"Author-Check- Article-or-Video","date":"August 12, 2015","format":false,"excerpt":"This post will be publish soon...........","rel":"","context":"In &quot;\u09aa\u09bf \u098f\u0987\u099a \u09aa\u09bf \u099f\u09bf\u0989\u099f\u09cb\u09b0\u09bf\u09df\u09be\u09b2 \u0964 PHP tutorial&quot;","block_context":{"text":"\u09aa\u09bf \u098f\u0987\u099a \u09aa\u09bf \u099f\u09bf\u0989\u099f\u09cb\u09b0\u09bf\u09df\u09be\u09b2 \u0964 PHP tutorial","link":"http:\/\/bangla.sitestree.com\/?cat=172"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65836,"url":"http:\/\/bangla.sitestree.com\/?p=65836","url_meta":{"origin":69920,"position":3},"title":"SCJP: Flow controls and exception #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"Flow Control and ExceptionsFlow control statements Conditional: if, if-else and switch-case Looping: for, while, do-while Exception handling: try-catch-finally, throw Ad hoc flow control: break, continue with or without labelsswitch statement switch(expression){ case ConstantExpression: statement(s); case ConstantExpression: statement(s); . . . default: statement(s); } expression: must be char, byte, short, or\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10104,"url":"http:\/\/bangla.sitestree.com\/?p=10104","url_meta":{"origin":69920,"position":4},"title":"Example Java Programs","author":"","date":"August 3, 2015","format":false,"excerpt":"HelloWorld.java public class HelloWorld { \u00a0\u00a0\u00a0 \/\/ method main(): ALWAYS the APPLICATION entry point \u00a0\u00a0\u00a0 public static void main (String[] args) { \u00a0\u00a0 \u00a0System.out.println (\"Hello World!\"); \u00a0\u00a0\u00a0 } } \/\/ Print Today's Date import java.util.*; public class HelloDate { \u00a0\u00a0\u00a0 public static void main (String[] args) { \u00a0\u00a0 \u00a0System.out.println (\"Hello,\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26864,"url":"http:\/\/bangla.sitestree.com\/?p=26864","url_meta":{"origin":69920,"position":5},"title":"Example Java Programs #Programming Code Examples #Java\/J2EE\/J2ME #J2SE","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"Very Simple Java Example Programs HelloWorld.java public class HelloWorld { \/\/ method main(): ALWAYS the APPLICATION entry point public static void main (String[] args) { System.out.println (\"Hello World!\"); } } \/\/ Print Today's Date import java.util.*; public class HelloDate { public static void main (String[] args) { System.out.println (\"Hello, it's:\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69920"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69920\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69920"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}