{"id":1090,"date":"2008-10-16T20:23:41","date_gmt":"2008-10-17T03:23:41","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/books\/?p=1090"},"modified":"2008-10-16T20:23:41","modified_gmt":"2008-10-17T03:23:41","slug":"1417-exception-handling","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/1417-exception-handling\/","title":{"rendered":"14.17 Exception Handling"},"content":{"rendered":"<h1>Handling Exceptions<\/h1>\n<p>Crystal Reports gives you the ability to handle any errors that might occur while printing and previewing. The benefit to handling the error yourself is that you can customize the error handling process. For example, you could write the error to a log file or you can gracefully exit the process without throwing an error message at the user.<\/p>\n<p>The CrystalReportViewer class has an Error() event that you can subscribe to. It is fired whenever an error occurs. This event has properties to tell you the exception information and give you the option to handle it yourself. Table 14-12 lists the properties for the ExceptionEventArgs() type.<\/p>\n<p>         <b>Table 14-12. Properties of the ExceptionEventArgs event type.<\/b><\/p>\n<table border=\"1\">\n<tr>\n<th>Property<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td>Exception<\/td>\n<td>The exception class for getting the error number and description.<\/td>\n<\/tr>\n<tr>\n<td>Handled<\/td>\n<td>Set to True if you do not want the standard error message shown.<\/td>\n<\/tr>\n<\/table>\n<p>Here is sample code for handling a report error.<\/p>\n<p>         <b>Listing 14-11. Handling report exceptions.<\/b><br \/>\n         <code>Private Sub CrystalReportViewer1_Error(ByVal source As System.Object, _<\/code><br \/>\n         <code>ByVal e As CrystalDecisions.Windows.Forms.ExceptionEventArgs) _<\/code><br \/>\n         <code>Handles CrystalReportViewer1.Error<\/code><br \/>\n         <code>\u2018put your code to handle the error here - maybe save to a log file?<\/code><br \/>\n         <code>\u2018\u2026<\/code><br \/>\n         <code>\u2018Tell the viewer that you handled the error and suppress the error message<\/code><br \/>\n         <code>e.Handled = True<\/code><br \/>\n         <code>End Sub<\/code><\/p>\n<p>If you aren&#8217;t using the viewer control, e.g. exporting reports, the ReportDocument class doesn&#8217;t have any error handling events associated with it. You will have to use the standard Try Catch method of trapping errors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Handling Exceptions Crystal Reports gives you the ability to handle any errors that might occur while printing and previewing. The benefit to handling the error yourself is that you can customize the error handling process. For example, you could write the error to a log file or you can gracefully exit the process without throwing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,40],"tags":[],"class_list":["post-1090","post","type-post","status-publish","format-standard","hentry","category-chapter-14-learning-the-report-object-models","category-crystal-reportsnet-2008","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/1090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=1090"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/1090\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=1090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=1090"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=1090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}