Both sides previous revisionPrevious revisionNext revision | Previous revision |
trycatch [2018/01/28 07:29] – wolfgangriedmann | trycatch [2018/08/20 04:05] (current) – wolfgangriedmann |
---|
====== Try - Catch ====== | ====== Try - Catch ====== |
| |
The ''Try - Catch'' block is very important, and should be used where an error can occurr, for example if a file that needs to be read does not exist, you are specifying an invalid path, the current user has not the rights to read and so forth - please read the documentation about [[https://docs.microsoft.com/en-us/dotnet/api/system.io.file.readalltext|System.IO.File.ReadAllText()]] to see what type of exceptions there are. | The ''Try - Catch'' block is very important, and should be used where an error can occur, for example if a file that needs to be read does not exist, you are specifying an invalid path, the current user has not the rights to read and so forth - please read the documentation about [[https://docs.microsoft.com/en-us/dotnet/api/system.io.file.readalltext|System.IO.File.ReadAllText()]] to see what type of exceptions there are. |
| |
In classic VO and Win32 applications, you had to check the return value of an operation, and then eventually ask for more details. | In classic VO and Win32 applications, you had to check the return value of an operation, and then eventually ask for more details. |
The .NET Framework works differently: it produces an exception, and it is the programmers responsability to treat it correctly. | The .NET Framework works differently: it produces an exception, and it is the programmers responsability to treat it correctly. |
| |
A sample:<code>using System.IO | A sample:<code visualfoxpro>using System.IO |
| |
function TestException() as void | function TestException() as void |
If you don't use the ''Try - Catch'' block, your program is terminated with a unspecified error, and you will not be able to understand what really occurred. | If you don't use the ''Try - Catch'' block, your program is terminated with a unspecified error, and you will not be able to understand what really occurred. |
| |
| Please see also here: [[exceptions|Exceptions]] |
| |
| |