Criando uma exception

O seu código pode criar uma exception com o comando throw. Normalmente as exceptions são criadas por bibliotecas. Veja um exemplo:

1
2
3
4
5
6
7
8
9
10
11
12
13
...
public object Pop()
{
      if (first == null)
            throw new Exception("Can't Pop from an empty Stack.");
      else
      {
            object teme = first.Value;
            first = first.Next;
            return teme;
      }
}
...

O comando throw é usado normalmente junto com as estruturas try/catch, mas isto não é uma regra.