[Question]
  [
We all know that if you google the word "google" it will break the internet.
Your task is to create a function that accepts one string and returns its length, in the fewest possible Unicode characters.
However, if the given string is `google` (lowercase), it will cause an error.
For example, `g('bing')` will return `4` but `g('google')` will cause an error.
Please provide an example of usage, and the error if possible.
  
[Answer]
## Python 2, 29
```
lambda x:len(x)/(x!='google')
```
Gives a `ZeroDivisionError` on `"google"`, and the length otherwise. This takes advantage of Python's booleans equaling `0` and `1`.
[Answer]
# Excel, 23 characters
Paste this into a cell other than A1 and type your search query into A1.
```
=LEN(A1)/(A1<>"google")
```
For example:
[![GoogleGoogle](https://i.stack.imgur.com/TseqO.png)](https://i.stack.imgur.com/TseqO.png)
[Answer]
# C#, 43 bytes
An improvement over Salah Alami's answer. Recurses to throw a stack overflow exception on providing "google"
```
int g(string s)=>s!="google"?s.Length:g(s);
```
[Answer]
# Pyth, ~~14~~ 13 characters
```
L/lbnb"google
```
Defines a named function `y`.
This divides the length by 1 if the string is not *google* and by 0 otherwise. The idea is not novel, but I came up with it independently.
[Try it online.](https://pyth.herokuapp.com/?code=L%2Flbnb"google"%0Ayz&input=google)
### How it works
```
L                 Define y(b):
  lb                Compute len(b).
    nb"google       Compute (b != "google").
 /                  Set _ = len(b) / (b != "google").
                  Return _. (implicit)
```
[Answer]
# MATLAB, ~~63~~ ~~41~~ ~~40~~ ~~38~~ 36 bytes
## Thanks to Tom Carpenter for shaving off 1 byte!
## Thanks to Stewie Griffin for shaving off 2 bytes!
```
@(x)nnz(x(+~strcmp('google',x):end))
```
Unlike the other more elegant solutions, performing a division by zero operation in MATLAB will not give an error, but rather `Inf`. This solution finds the length of the string by `nnz`. The string that is produced is in such a way that you index from the beginning of the string to the end, which is essentially a copy of the string. However, what is important is that the beginning of where to access the string is produced by checking whether or not the input is equal to `'google'`. If it isn't, this produces a beginning index of 1 and we index into the string normally... as MATLAB starts indexing at 1. Should it be equal, the index produced is 0 and MATLAB will throw an indexing error stating that the index needs to be a positive integer. The extra `+` is to ensure that the output of the equality check is numerical rather than Boolean/`logical`. Omitting the `+` will produce a warning, but because this challenge's specifications doesn't allow for warnings, the `+` is required... thus completing the code.
# Example uses
```
>> f=@(x)nnz(x(+~strcmp('google',x):end)) %// Declare anonymous function
f = 
    @(x)nnz(x(+~strcmp('google',x):end))
>> f('bing')
ans =
     4
>> f('google')
Subscript indices must either be real positive integers or logicals.
Error in @(x)nnz(x(+~strcmp('google',x):end))
```
---
# A more fun version, ~~83~~ ~~77~~ ~~76~~ ~~74~~ 72 bytes
## Thanks to Tom Carpenter for shaving off 1 byte!
## Thanks to Stewie Griffin for shaving off 2 bytes!
```
@(x)eval('if strcmp(''google'',x),web([x ''.com/i'']);else nnz(x),end');
```
The above isn't an official submission, but it's something that's a bit more fun to run. Abusing `eval` within anonymous functions, what the code does is that it checks to see if the input string is equal to `'google'`... and if it is, this will open up MATLAB's built-in web browser and shows Google's 404 error page trying to access the subpage located at `i` when that doesn't exist. If not, we display the length of the string normally.
# Example uses
```
>> f=@(x)eval('if strcmp(''google'',x),web([x ''.com/i'']);else nnz(x),end'); %// Declare anonymous function
>> f('bing')
ans =
     4
>> f('google')
>> 
```
The last call using `'google'` gives us this screen:
[![enter image description here](https://i.stack.imgur.com/qrUWW.png)](https://i.stack.imgur.com/qrUWW.png)
[Answer]
# JavaScript ES6, ~~34~~ ~~27~~ 25 characters
```
f=>f=='google'?Δ:f.length
```
Throws a ReferenceError on `Δ` for google.
```
alert((f=>f=='google'?Δ:f.length)('test'))
```
[Answer]
# TI-BASIC, 15 bytes
Heck, while [we're at it](https://codegolf.stackexchange.com/questions/58891/dont-google-google#comment141887_58895), might as well get a TI-BASIC answer in here.
Input format is `"string":prgmNAME`. Credit to [Thomas Kwa](https://codegolf.stackexchange.com/users/39328/thomas-kwa) for finding it first!
```
length(Ans)+log(Ans≠"GOOGLE
```
(Guide: add 1 byte for each lowercase letter replacing an upper-case one. So `s/GOOGLE/google/g => +6 bytes`.)
### ahhhhh test cases!
```
"GOGGLE":prgmG
               6
"BING":prgmG
               4
"GOOGLE":prgmG
           Error
```
[Answer]
# Python 3, 30 bytes
```
lambda u:[len][u=='google'](u)
```
Indexes the 1-element function list, raising an `IndexError` if the `u=='google'` predicate is `True` (= 1). Such functional.
Much variants. Wow:
```
lambda u:[len(u)][u=='google']
lambda u:len([u][u=='google'])
```
> 
> If the challenge was inverted (error on everything *not* "google"), could save a char:
> 
> 
> 
> ```
> lambda u:{'google':len}[u](u)
> 
> ```
> 
> But you already know the length, so just hardcode it.
> 
> 
> 
[Answer]
# APL (14)
```
(⍴÷'google'∘≢)
```
Explanation:
* `⍴`: length
* `÷`: divided by
* `'google'∘≢`: argument is not equal to `'google'`.
`⍴` gives the length of the string, which is divided by 1 if the string does not equal `google` (which gives the length back unchanged), or by 0 if the string *does* equal `google` (giving an error).
[Answer]
## Haskell, 24 bytes
`g s|s/="google"=length s`
Output:
```
Main> g "google"
Program error: pattern match failure: g "google"
Main> g "bing"
4
```
[Answer]
# Octave, 63 bytes
I know it is longer than the Matlab solution (which would work in Octave too), but it is particularly evil. I am making an anonymous function (evil) using cell array (evil) literals (evil) containing function handles dependent on a callback function (itself, thus recursive, evil) that must be passed via argument. Then I create another anonymous that basically reduces the function to the string argument and fixes the second argument of `f` as `f` (very evil). Any sane human would never do this, because it is almost as unreadable as Perl or regex (or cjam/pyth/any other esolang).
So if the string is not 'google' the second argument of the cell array will be called which outputs the length of the string. Otherwise the first function will be called, which is passed as a callback (and passes itself as callback to itself too) which later is the function itself. The error is basically some maximum recursion depth error.
```
f=@(s,f){@()f(s,f),numel(s)}{2-strcmp(s,'google')}();@(s)f(s,f)
```
[Answer]
# CJam, 16 characters
```
{_,\"google"=!/}
```
This divides the length by 1 if the string is not *google* and by 0 otherwise. The idea is not novel, but I came up with it independently.
[Try it online.](http://cjam.aditsu.net/#code=q%20e%23%20Read%20input%20from%20STDIN.%0A%0A%7B_%2C%5C%22google%22%3D!%2F%7D%0A%0A~%20e%23%20Execute%20the%20function.&input=google)
### How it works
```
_                 Push a copy of the string on the stack.
 ,                Compute the length of the copy.
  \               Swap the length and the original string.
   "google"=      Push 1 if the string is "google", 0 otherwise.
            !     Apply logical NOT. Maps 1 to 0 and 0 to 1.
             /    Divide the length by the Boolean.
```
[Answer]
# APL, ~~19~~ 17 bytes
```
{⍵≡'google':⍟⋄≢⍵}
```
This is an unnamed monadic function that will throw a syntax error if the input is `google`. This is accomplished by attempting to take the natural logarithm of nothing.
```
{
 ⍵≡'google':          ⍝ If the right argument is "google"...
            ⍟⋄        ⍝ Compute log(<nothing>), which brings only sadness
              ≢⍵      ⍝ Otherwise compute the length
}
```
[Try it online](http://tryapl.org/?a=%7B%u2375%u2261%27google%27%3A%u235F%u22C4%u2262%u2375%7D%27bing%27%u22C4%7B%u2375%u2261%27google%27%3A%u235F%u22C4%u2262%u2375%7D%27google%27&run)
Saved two bytes thanks to Dennis!
[Answer]
# JavaScript, 25 Bytes
Nice and simple JavaScript example:
```
e=>e!='google'?e.length:g
```
If "google" is entered then it passes a `ReferenceError`
Example
```
alert((e=>e!='google'?e.length:g)('test'))
```
[Answer]
# R, 46 bytes
```
g=function(x)ifelse(x!="google",nchar(x),)
```
Unless I'm misreading, the original post never specified that the code had to be correct syntax.
Example:
```
> g("bing")
[1] 4
> g("google")
Error in ifelse(x != "google", nchar(x), ) : 
  argument "no" is missing, with no default
```
I never added anything for the "no" parameter of the ifelse statement so it will return an error if this parameter is evoked.
[Answer]
# Perl, ~~31~~ 29 bytes
```
sub{$_=pop;y///c/!/^google$/}
```
-2b thanks to manatwork
Usage:
```
sub{$_=pop;y///c/!/^google$/}->("google")
```
---
If I could get away with a program rather than a function, the following would be valid with only 20 bytes (+1 byte command line)
```
$_=y///c/!/^google$/
```
Error is division by zero.
Explanation:
`y///c` returns the length, then `!/^google$/` will return 0 iff input matches 'google'.
Usage:
```
perl -p entry.pl input.txt
```
[Answer]
# Java 7:~~53~~ 52 Bytes
```
int g(String _){return"google"==_?0/0:_.length();} 
```
Above code will throw `ArithmeticException` for division by zero and for any `String` other than `google`. Worth to note that `==` compares reference and won't work for `String` Objects.
# Java 8 : 29 Bytes
(Based on suggestion given in below comment)
```
s->s=="google"?0/0:s.length()
```
[Answer]
## Haskell - 30 characters
```
g"google"=error"!";g s=length s
>g "google"
 *Exception: !
>g "str"
 3
```
[Answer]
# Python 3, 35 bytes
```
lambda n:len(n)if n!='google'else d
```
[Answer]
# C++11, 54 (code) + 14 (#include) = 68
Well, division by zero is just undefined behaviour, which I would not call an error. So my approach.
```
#include<ios>
[](std::string s){return s!="google"?s.size():throw;};
```
usage
```
[](std::string s){return s!="google"?s.size():throw;}("google");
```
[Answer]
**C, 66 48**
*Original:*
```
int l(long*s){return strlen(s)/((*s&~(-1L<<56))!=0x656c676f6f67);}
```
Using OSX gcc,  
`l("duck");` returns `4`,  
`l("google");` causes `Floating point exception: 8`. 
On other platforms, the constants may need to be adjusted for endianness.
*Shorter*:
less trickyness, same results.
```
 l(int*s){return strlen(s)/!!strcmp(s,"Google");}
```
[Answer]
# Ruby, 29 bytes
I first came up with something very similar to @Borsunho's first attempt, but mine was slightly longer and he posted his before I was done. Came up with this before his 30 bytes edit :)
```
->s{s[/^(?!google$).*/].size}
```
Usage examples:
```
$ irb
2.2.1 :001 > f = ->s{s[/^(?!google$).*/].size}
 => #<Proc:0x007fa0ea03eb60@(irb):1 (lambda)> 
2.2.1 :002 > f[""]
 => 0 
2.2.1 :003 > f["bing"]
 => 4 
2.2.1 :004 > f["google"]
NoMethodError: undefined method `size' for nil:NilClass
  from (irb):1:in `block in irb_binding'
  from (irb):4:in `[]'
  from (irb):4
  from /Users/daniel/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
```
---
edit: Two years and some Ruby versions later
# [Ruby](https://www.ruby-lang.org/), 25 bytes
```
->s{+s[/^(?!google$).*/]}
```
Replaced `String#size` with the new unary plus. [Try it online!](https://tio.run/##KypNqvyfZvtf1664Wrs4Wj9Ow14xPT8/PSdVRVNPSz@29n@BQlq0UkZqpVIsF5gJkVWK/Q8A "Ruby – Try It Online")
[Answer]
# MUMPS, 28 bytes
```
g(s) q $S(s'="google":$L(s))
```
Usage:
```
>w $$g^MYROUTINE("bing")                                      
4
>w $$g^MYROUTINE("google")
<SELECT>g^MYROUTINE
```
Why? Well, `$S[ELECT]` is basically a compact multi-clause if-else statement - almost like a pattern-match in a language like Haskell or Rust. Except... unlike in Haskell or Rust, the patterns aren't checked for exhaustiveness, because the notion of "compile-time safety" is completely alien to MUMPS. So if your input is a pattern you didn't account for, you get a lovely runtime error called `<SELECT>`.
[Answer]
# JavaScript, 47 bytes
Nice and simple.
***Edit:*** Now complies with the rules
```
function f(g){if(g=="google")a;return g.length}
```
## Testing
### Error thrown
```
function f(g){if(g=="google")a;return g.length}
alert(f("Hello"))
alert(f("google"))
alert(f("hi"))
```
### No error thrown
```
function f(g){if(g=="google")a;return g.length}
alert(f("Hello"))
alert(f("bing"))
alert(f("hi"))
```
[Answer]
# Ruby, ~~34~~ ~~30~~ ~~27~~ 26
```
->x{x=='google'?t: x.size}
```
Unknown `t` raises exception.
```
->x{x=='google'?fail():x.size}
```
Edit: totally readable and obvious version that is shorter...
```
->x{x[x=~/^(?!google$)/..-1].size}
```
Old: Pretty similar to other ideas it seems. Will raise `ArgumentError` if x is 'google'.
[Answer]
# C - ~~99 75 67~~ 63 bytes
```
g(char*s){int i=0,j=*s;while(s[i])j^=s[++i];return j^9?i:g(s);}
```
## Ungolfed:
```
int g(char *s){
    int i = 0,
        j = s[0]; // first char of s
    while(s[i] != '\0'){
        j ^= s[++i]; // j = j XOR [next char]
    }
    if(j != 9){ // g^o^o^g^l^e = 9
        return i;
    } else {
        g(s); // infinite recursion
    }
}
```
Using it:
```
g("bing")       // 4
g("duckduckgo") // 10
g("google")     // segmentation fault
```
Will return the length if `g XOR o XOR o XOR g XOR l XOR e` isn't `9`, else it will infinite recurse causing a stack overflow.
## How it works
I used a (very) crappy hashing algorithm (`a XOR b XOR c ...`) to get a single number from the first six chars of the string. Collision likelyhood is very high, but if we assume the string has to be the name of an actual search engine, then the collision likelyhood is fairly low.
So, first we have `i`, which iterates through the string until `s[i]` is `NUL` (0), and while counting the length of the string, the selected char is XOR'd onto `j`, which is initialized to the first char in s. For "google", the result of this operation is 9.
The main thing this takes advantage of is the way pointers work in C. A pointer is actually a large number that denotes an address in memory, `&var` will return a pointer to `var`, while `*var` will dereference a pointer (grab the value at that address). Thus, `*s` is equivalent to `s[0]`. I think this is where most beginners get lost, confused and frustrated when it comes to C, like when you try to send a `struct *` to a function that takes `struct *` by sending `&struct_ptr`, which would be a memory address to a memory address, effectively making the compiler give an error such as `function expects 'struct *' but got 'struct **'`.
[Answer]
# Windows Batch, 118 characters
```
IF /I "%string%"=="google" exit
echo %string%> string.txt
for %%? in (string.txt) do ( SET /A stringlength=%%~z? - 2 )
```
Output is %stringlength%.
Full code:
```
@echo off
del string.txt
cls
echo Type your string
echo.
set /p string=String:
IF /I "%string%"=="google" goto err
echo %string%> string.txt
for %%? in (string.txt) do ( SET /A stringlength=%%~z? - 2 )
cls
echo %stringlength%
pause
del string.txt
:err
color c
echo There seems to be an error with your input...
pause>nul
```
Modified from Joshua Honig's answer, [here](https://stackoverflow.com/a/8566001/4910495).
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
U¥`goog¤`?Þ:Ul
```
[Try it here!](http://ethproductions.github.io/japt/?v=1.4.3&code=VaVgZ29vZ6RgP946VWw=&input=Imdvb2dsZSI=)
### Explanation
```
U¥`goog¤`?Þ:Ul  
U                     // U is the input
 ¥                    // ¥ is the Unicode shortcut for ==
  goog¤               // "google" compressed
 `      `             // backticks are used to uncompress goog¤
          Þ           // An undefined variable
            Ul        // l is a built-in that returns the length of U
                      // Implicit: output result of last expression
```
[Answer]
# [Zsh](https://www.zsh.org/), 18 bytes
```
<<<$#1>$1
<^google
```
[Try it online!](https://tio.run/##qyrO@F@cWpJfUKKQWlGSmpeSmpKek5/038bGRkXZ0E7FkMsmLj0/Pz0n9f///2AGAA "Zsh – Try It Online")
Explanation:
* `<<<$#1`:
	+ `$1`: the input
	+ `#`: length
	+ `<<<`: and print it
* `>$1`: redirect that output to a file called the input
* `^google`: try and find a file with any name other than `google`
* `<`: and print its contents
So if the file created was called `google`, then no file will be found and an error message will appear. But if the file was called anything else, then its contents is the length of the input, and it will be outputted.
[Answer]
## ><>, 55 bytes
```
i:0(?v
31&l~<v0"google"~~.?%2l
$v?(2l<S?*=2l=6:+={
&<;n
```
Figured I'd give this a go, not my best golfing attempt or algorithm, though. Not a function per se, but I think that this should still qualify. I'll see if I can edit in a better version.
If you're allowed to print the length and then error, here's a 46 byte solution:
```
i:0(?v
2lnl~<v0"google";?%
$;?(2l<S?*=2l=6:+={
```
49 byte previous solution of this nature:
```
i:0(?v
l0nl~<v;!?=7
:;?(2l<S?*=2l=6:+=@@g3
elgoog
```
I'm happy to put up an explanation if there's any interest, and please let me know if there's anything wrong with my answer or if you have golfing suggestions.
]