Thursday, January 18th, 2007

throw null

Thursday, January 18th, 2007 03:45 pm
flwyd: (java logo)

I saw some typo Java code in my CVS update today which called throw null. I wondered just what that would do. null can be cast to any object, so I thought it might get caught by the first catch clause. Alternatively, I thought it might escape all catch clauses (dangerous!). The answer?

	try {
	    throw null;
	} catch (IllegalArgumentException e) {
	    System.err.println("Caught IllegalArgumentException " + e);
	    e.printStackTrace();
	} catch (NullPointerException e) {
	    System.err.println("Caught NullPointerException " + e);
	    e.printStackTrace();
	} catch (Throwable t) {
	    System.err.println("Caught Throwable " + t);
	    t.printStackTrace();
	}

Caught NullPointerException java.lang.NullPointerException
java.lang.NullPointerException
	at TestStuff.main(TestStuff.java:156)

Java (even pre-1.5) automatically creates a NullPointerException if you throw null. It's like very specialized autoboxing.

Football is Tame

Thursday, January 18th, 2007 08:30 pm
flwyd: (Vigelandsparken circle man)
People have criticized American Football for being a violent sport. But the following passage from Egil's Saga, chapter 40, shows that today's ball games are nowhere near as violent as they could be.

A ball game was arranged early in winter on the plains by the river Hvita, and crowds of people came to it from all over the district. Many of Skallagrim's men attended, and Thord Granason was their leader. Egil asked Throd if he could go to the game with him; he was in his seventh year then. Thord let him, and seated Egil behind him when he rode there.

When they reached the games meeting, the players were divided up into teams. A lot of small boys were there as well, and they formed teams to play their own games.

Egil was paired against a boy called Grim, the son of Hegg from Heggstadir. Grim was ten or eleven years old, and strong for his age. When they started playing the game, Egil proved to be weaker than Grim, who showed off his strength as much as he could. Egil lost his temper, wielded the bat and struck Grim, who seized him and dashed him to the ground roughly, warning him that he would suffer for it if he didn't learn how to behave. When Egil got back on his feet he left the game, and the boys jeered at him.

Egil went to see Thord Granason and told him what had happened.

Thord said, 'I'll go with you and we'll take our revenge.'

Thord handed Egil an axe he had been holding, a common type of weapon in those days. They walked over to where the boys were playing their game. Grim had caught the ball and was running with the other boys chasing him. Egil ran up to Grim and drove the axe into his head, right through to the brain. Then Egil and Thord walked away to their people. The people from Myrar seized their weapons, and so did the others. Oleif Hjalti rushed to join the people from Borg with his men. Theirs was a much larger group, and at that the two sides parted.


I'm sure everyone's glad that the Vikings aren't in the playoffs.
March 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 2026

Most Popular Tags

Expand Cut Tags

No cut tags
Page generated Tuesday, March 31st, 2026 03:23 pm
Powered by Dreamwidth Studios