User Tools

Site Tools


exceptions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
exceptions [2018/01/28 17:24] wolfgangriedmannexceptions [2018/03/25 17:47] (current) wolfgangriedmann
Line 10: Line 10:
 cString := "Hello world" cString := "Hello world"
 cResult := cString:Substring( 5, 30 )</code> cResult := cString:Substring( 5, 30 )</code>
-Since the string is less than 35 characters long, this code produces an OutOfRangeException.+Since the string is less than 35 characters long, this code produces an OutOfRangeException and terminates your program.
  
 So, when using this method on strings, you have a few possibilities: So, when using this method on strings, you have a few possibilities:
   * use this method only enclosed in a ''try-catch'' block   * use this method only enclosed in a ''try-catch'' block
   * check the string length and adjust the parameters accordingly   * check the string length and adjust the parameters accordingly
-  * or use an own method (for example a static method or an [[attached_methods|Attached method]] of the System.String class+  * or use an own method (for example a static method or an [[extension_methods|Extension methods]] of the ''System.String'' class)
  
 +Exception handling is very important in the .NET Framework. In every place where an error can occur, you should provide exception handling. If you don't provide it, at runtime the application will crash without details about the error.
 +There are also a few application wide handlers you can install (and your should use them):
 +  * [[https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.unhandledexception?|AppDomain.UnhandledException]]: handles otherwise unhandled exceptions
 +  * [[https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.application.threadexception|Application.ThreadException]]: handles exceptions in Windows Forms applications
 +  * [[https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception|Application.DispatcherUnhandledException]]: handles exceptions in the WPF GUI
 +
 +You can find a note about these also in the X# forum: [[https://www.xsharp.info/forum/public-vo-vn/310-suggestions-for-conversion-vo-programs-using-vo-gui-classes?start=10|Handling exceptions by Paul Piko]]
 +
 +There are several publicily available exception handlers like [[https://logging.apache.org/log4net/|Apache log4net]] or [[https://msdn.microsoft.com/en-us/library/ff649552.aspx|Exception Handling Application Block]] in the Enterprise Library.
 +
 +Nevertheless here is a small collection of simple exception handlers:
 +  * [[write_exception_log|Write an exception to a log file]]
 +  * [[exception_handler_vogui|Exception handler for a VO GUI application]]
 +  * [[exception_handler_winforms|Exception handler for a WinForms application]]
 +  * [[exception_handler_wpf|Exception handler for a WPF application]]
  
exceptions.1517160277.txt.gz · Last modified: 2018/01/28 17:24 by wolfgangriedmann