Using ಠ_ಠ to Throw Exceptions
Posted by Andy Kutruff on February 8, 2011
Most people don’t know that you can oftentimes put Unicode characters in your code. However, the look of disapproval is gold, and I am now going to use it to throw exceptions.
C# version:
public static void ಠ_ಠ(string error)
{
throw new Exception(error);
}
public static void CreateFile(string path)
{
if(File.Exists(path))
{
ಠ_ಠ("error: file exists")
}
File.Create(path)
}
F# version
open System.IO
let ಠ_ಠ = failwith
let createFile path =
if File.Exists(path) then
ಠ_ಠ "error: file exists"
File.Create(path)
Note: This is inspired from a practical joke from some coworkers in the past. Someone apparently snuck in a method named _μ into the code. That is “underscore mu” and apparently it drove people nuts.
Trevor said
This works in Python 3.0+ as well:
#!/usr/bin/env python3.2
# coding=utf-8
def ಠ_ಠ(err):
raise Exception(err)
ಠ_ಠ("herp derp")
hawth said
For ruby 1.9
# encoding: utf-8
def ಠ_ಠ message
raise Exception, message, caller
end
ಠ_ಠ “file not found”
look_of_dissaproval.rb:7:in `’: file not found (Exception)
Tweets that mention Using ಠ_ಠ to Throw Exceptions « Andy Kutruff -- Topsy.com said
[...] This post was mentioned on Twitter by Carlos Benítez, Jimmy L., Jeremy Mikola, Jeremy Mikola, Tech news (BOT) and others. Tech news (BOT) said: Reddit/p: Using ಠ_ಠ to Throw Exceptions http://bit.ly/iaEbMP [...]
TJ GIllis said
Works in as3
private function ಠ_ಠ():void{}
luben said
#!/usr/bin/perl
use utf8;
sub ಠ_ಠ { die @_ }
ಠ_ಠ(“I’m sad”)
Matt said
Works in PHP 5.3:
<?php function ಠ_ಠ ($foo) { echo("foo + 1 == " . ($foo + 1) . "\n"); } ಠ_ಠ (5);Scott said
function ಠ_ಠ(err) {
console.error(err);
};
ಠ_ಠ(“error”);
jaykul said
Works in PowerShell, if you’re using a unicode-capable host like PowerShell ISE or PoshConsole
You can either:
or:
function ಠ_ಠ { throw $args }In either case:
jaykul said
That should read:
You can’t set an alias for throw in PowerShell.
Mastur B. said
It is more satisfying to embed SHIFT-JIS encoded strings into class names.
Simon said
Works in R
.
>ಠ_ಠ <- function(x) { stop(as.character(x)) }
Example:
> sapply(1:5, function(x) { if (x == 5) ಠ_ಠ(x) })
Error in ಠ_ಠ(x) : 5
Bob said
getMessage() . ” It won’t happen again\n”;
}
?>
Bob said
This time with feeling:
function ಠ_ಠ($error)
{
throw new Exception($error);
}
try
{
ಠ_ಠ("I'm so sorry.");
}
catch (Exception $e)
{
echo $e->getMessage() . " It won't happen again\n";
}
Henrik N said
Ruby 1.8:
https://gist.github.com/820190
gogo said
Golang version:
func ಠ_ಠ(s string){
panic(s)
}
Casey said
Thanks for this, made my day!
Michael Geary said
JavaScript version:
hemanth said
function ಠ_ಠ
{
echo “Bomb!”
}
Works in BASH
Buvinghausen said
Decided to make a jQuery script based on this
https://gist.github.com/3351460