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.
19 responses to “Using ಠ_ಠ to Throw Exceptions”
This works in Python 3.0+ as well:
#!/usr/bin/env python3.2
# coding=utf-8
def ಠ_ಠ(err):
raise Exception(err)
ಠ_ಠ("herp derp")
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)
[…] 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 […]
Works in as3
private function ಠ_ಠ():void{}
#!/usr/bin/perl
use utf8;
sub ಠ_ಠ { die @_ }
ಠ_ಠ(“I’m sad”)
Works in PHP 5.3:
function ಠ_ಠ(err) {
console.error(err);
};
ಠ_ಠ(“error”);
Works in PowerShell, if you’re using a unicode-capable host like PowerShell ISE or PoshConsole
You can either:
or:
In either case:
That should read:
You can’t set an alias for throw in PowerShell.
It is more satisfying to embed SHIFT-JIS encoded strings into class names.
Works in R :).
>ಠ_ಠ <- function(x) { stop(as.character(x)) }
Example:
> sapply(1:5, function(x) { if (x == 5) ಠ_ಠ(x) })
Error in ಠ_ಠ(x) : 5
getMessage() . ” It won’t happen again\n”;
}
?>
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";
}
Ruby 1.8:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
look_of_disapproval.rb
hosted with ❤ by GitHub
Golang version:
func ಠ_ಠ(s string){
panic(s)
}
Thanks for this, made my day! 😀
JavaScript version:
function ಠ_ಠ
{
echo “Bomb!”
}
Works in BASH 🙂
Decided to make a jQuery script based on this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gistfile1.html
hosted with ❤ by GitHub