Initial commit
This commit is contained in:
26
11.1-Exceptions/Exceptions.cs
Normal file
26
11.1-Exceptions/Exceptions.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
class Exceptions {
|
||||
public static void Main() {
|
||||
int[] arr = new int[5];
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
arr[i] = i * 2;
|
||||
}
|
||||
Console.WriteLine("Innehallet i arrayen");
|
||||
|
||||
try {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Console.WriteLine("Array[{0}]: {1}", i, arr[i]);
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfRangeException iob) {
|
||||
Console.WriteLine("Du vet val att man inte kan loopa utanfor en array?");
|
||||
Console.WriteLine(iob);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Console.WriteLine("Nagot bidde fel");
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user