[Question]
  [
# Task
Given a non-negative number, check if it's odd or even. In case it's even, output that number. Otherwise, throw any exception/error that your language supports, and stop the program.
# Example with Python
Input: `1`  
Output:
```
Traceback (most recent call last):
  File ".code.tio", line 1, in <module>
    IfYouWantThenThrowThis
NameError: name 'IfYouWantThenThrowThis' is not defined
```
# Another example
Input: `2`  
Output: `2`
# Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the answer with shortest bytes wins.
* [These](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) loopholes are, obviously, forbidden.
* Standard code-golf rules apply.
* Please specify the language you are using and the amount of bytes.
* It would be great if you would put a link to a sandbox where your code can be ran in action, such as [TIO](https://tio.run).
* Explaining your code is very welcomed.
---
# LEADERBOARD
```
<script>var QUESTION_ID=229052,OVERRIDE_USER=0;</script><style>body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script>var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(d,e){return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){answers.push.apply(answers,d.items),answers_hash=[],answer_ids=[],d.items.forEach(function(e){e.comments=[];var f=+e.share_link.match(/\d+/);answer_ids.push(f),answers_hash[f]=e}),d.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){d.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),d.has_more?getComments():more_answers?getAnswers():process()}})}getAnswers();var SCORE_REG=function(){var d=String.raw`h\d`,e=String.raw`\-?\d+\.?\d*`,f=String.raw`[^\n<>]*`,g=String.raw`<s>${f}</s>|<strike>${f}</strike>|<del>${f}</del>`,h=String.raw`[^\n\d<>]*`,j=String.raw`<[^\n<>]+>`;return new RegExp(String.raw`<${d}>`+String.raw`\s*([^\n,]*[^\s,]),.*?`+String.raw`(${e})`+String.raw`(?=`+String.raw`${h}`+String.raw`(?:(?:${g}|${j})${h})*`+String.raw`</${d}>`+String.raw`)`)}(),OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(d){return d.owner.display_name}function process(){var d=[];answers.forEach(function(n){var o=n.body;n.comments.forEach(function(q){OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>")});var p=o.match(SCORE_REG);p&&d.push({user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link})}),d.sort(function(n,o){var p=n.size,q=o.size;return p-q});var e={},f=1,g=null,h=1;d.forEach(function(n){n.size!=g&&(h=f),g=n.size,++f;var o=jQuery("#answer-template").html();o=o.replace("{{PLACE}}",h+".").replace("{{NAME}}",n.user).replace("{{LANGUAGE}}",n.language).replace("{{SIZE}}",n.size).replace("{{LINK}}",n.link),o=jQuery(o),jQuery("#answers").append(o);var p=n.language;p=jQuery("<i>"+n.language+"</i>").text().toLowerCase(),e[p]=e[p]||{lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p}});var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o){return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0});for(var l=0;l<j.length;++l){var m=jQuery("#language-template").html(),k=j[l];m=m.replace("{{LANGUAGE}}",k.lang).replace("{{NAME}}",k.user).replace("{{SIZE}}",k.size).replace("{{LINK}}",k.link),m=jQuery(m),jQuery("#languages").append(m)}}</script><link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), 16 bytes
```
lambda n:n<<n%-2
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPKs/GJk9VFyiYX6SQp5CZpxBtqGOkY6xjomMaa8WlUFCUmVeikKfDpVBSVAnkQwXSNPI0uRRSK5JTC0oUwhJzSlNdi4ryixAKlMB8Ja7/AA "Python 2 ‚Äì Try It Online")
The expression `n%-2` equals 0 for even `n` and -1 for odd `n`. Bit-shifting `n` by 0 positions leaves it unchanged, but for -1 positions it gives an error for "negative shift count".
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
M·∏Ç¬°
```
[Try it online!](https://tio.run/##y0rNyan8/9/34Y6mQwv///9vBAA "Jelly ‚Äì Try It Online") (even) and [Try it online!](https://tio.run/##y0rNyan8/9/34Y6mQwv///9vDAA "Jelly ‚Äì Try It Online") (odd)
## How it works
`M` is an atom meaning "Given a list, yield the indices of that maximal elements". Now, typically, when given integer arguments to its array functions, Jelly promotes them to either a range, to digits, or just wraps it. Unfortunately, (I'm guessing due to `M`'s age - it was one of the earliest builtins in Jelly), `M` doesn't do this, and throws an error as it can't iterate over an integer.
How the code actually works:
```
M·∏Ç¬° - Main link. Takes N on the left
 ·∏Ç  - Bit; Calculate N % 2
  ¬° - Do the following a number of times equal to N % 2:
M   -   Run the M builtin on N
```
If the input `N` is even, then `·∏Ç` yields `0` and `¬°` runs `M` on `N` `0` times i.e. an identity function.
If the input is odd, then `·∏Ç` yields `1` and `¬°` runs `M` once, which is enough to error it
[Answer]
# [Hexagony](https://github.com/m-ender/hexagony), 13 bytes
```
?#\.@!:.!_@\|
```
[Try it online!](https://tio.run/##y0itSEzPz6v8/99eOUbPQdFKTzHeIabm/38LS0MjY3MTC0tjE0MLI0tjU3NDC0ugiKkFUNzS3ATMAzEtoOrAFIRnClUJAA "Hexagony ‚Äì Try It Online")
Expanded: (Made using [Hexagony Colorer](https://github.com/Timwi/HexagonyColorer))
[![Hexagony Colorer Map](https://i.stack.imgur.com/g1mGK.png)](https://i.stack.imgur.com/g1mGK.png)
This code is built around Hexagony's `#` operator. Hexagony initializes with 6 IP's, 1 in each corner of the code box, with the 0th one, the one in the top left, being active in the beginning. The `#` operator takes the value of the current memory cell mod 6, and then sets the corresponding IP as the active one. So making an even/odd checker is a matter of using the `#` operator and then having IP's 1,3, and 5 perform the 'odd' action, and IP's 0,2, and 4 perform the 'even' action. The consequence of doing it this way is that there are 6 separate paths that each need to be mapped to the correct endpoint, hence the mess of paths. In this case, the odd action is `:` (attempt to divide two non-existent values, resulting in a divide by zero error) and the even action is `!@` (print and terminate). To make it hopefully a bit more readable, here's a very low-tech drawing of the paths:
[![Hand-drawn map](https://i.stack.imgur.com/lhX32.jpg)](https://i.stack.imgur.com/lhX32.jpg)
The paths are:
* n%6 == 0 : Green
* n%6 == 1 : Yellow
* n%6 == 2 : Blue
* n%6 == 3 Pink
* n%6 == 4 : Orange
* n%6 == 5 : Red
I'm pretty confident 12 bytes is possible, and potentially even shorter. Not sure if there's a better approach entirely, but with this method, it seems just about brute-force-able. It seems it should only require `?`,`#`, no more than 3 each of `@`,`!`, and `:`, and some control flow characters.
[Answer]
# x86 Machine Code, 5 bytes
```
A8 01 74 01 F4
```
Takes the integer value of your choice in the `EAX` register, halts the CPU if the number is odd, or continues execution harmlessly if the number is even.
Ungolfed assembly language mnemonics:
```
A8 01         test   al, 1
74 01         jz     IsEven
F4            hlt
          IsEven:
```
The first two instructions (`test`+`jz`) are the fastest and smallest way to check whether an integer value is even or odd in x86 machine code. The reason they work is hopefully obvious: for binary numbers, the least-significant bit (bit 0) is only set if the number is odd (for even numbers, the least-significant bit is clear). Therefore, testing the least-significant bit and seeing if it is non-zero is the easiest, simplest, smallest, and fastest way to see whether a number is even.
Here, I've used `jz` to jump if the zero flag (ZF) is set‚Äîi.e., if the bit we tested (bit 0) was zero, which means that it jumps if the number was even. Note that it jumps *over* the halt (`hlt`) instruction if the input value was even. If the input value was odd, then execution falls through the jump, and ends up halting the CPU.
If you don't like `hlt` because you don't think that counts as throwing an exception/error, then replace it with an `int 3` instruction, which is also only 1 byte (`0xCC`), and thus doesn't change the overall code size (5 bytes). The `int 3` instruction is the trap to a debugger.
The only way you could really argue that this code is cheating is that it doesn't "output" that number. I'd say it does: it allows execution to continue past the point where that number was generated, which is a lot like outputting it. You don't get any output for odd inputs; you can only get output for even inputs. Besides that, I think this is allowed by many, many different [agreed-upon input/output methods](https://codegolf.meta.stackexchange.com/q/2447).
---
# x86 Machine Code, 6 bytes (non-competing)
A division by 0 is another obvious solution, but it doesn't save any bytes. Even if you are willing to allow clobbering the input value, in order to arrange for a division by zero, you have to negate somewhere (either the original value, or the isolated LSB), and that requires an extra instruction (either `XOR`ing with 1, or a `NOT`), which means 2 extra bytes.
```
A8 01         test   al, 1
34 01         xor    al, 1
F6 F0         div    al
```
That's 6 bytes, and I'm not even sure that I can figure out how to justify this clobbering of the original input value as being consistent with the requirements of the challenge to "output" the value.
To avoid clobbering, there are a few different options. For example, we can stipulate that the input is taken in a different register (say, `ECX`). But this means that we can't use the short "implied accumulator" encoding of `test` and `xor`, so it costs us at least two bytes. (We could use `not` with the full register before the `test` to invert the bits, which is encoded in only 2 bytes, but that defeats the point, which is to avoid clobbering the input.) Or, we could `push` and `pop` the input, but that also costs two extra bytes (one for each, `push` and `pop`). Maybe I'm missing something obvious, but I'm not seeing a better solution here.
[Answer]
# [Java (JDK)](http://jdk.java.net/), 10 bytes
```
n->n/=~n&1
```
[Try it online!](https://tio.run/##fVA9T8MwEN3zK54qBTmUGMrYECQGBoaKoWJCDK7jBIfEtuxLRYTKXw8mohUDYrl7p/dxp2vFXuRt9Tbp3llPaOPMB9IdrwcjSVvDz4tEdiIEbIQ2@EgAN@w6LRFIUGx7qyv0kWNb8to0zy8QvgnZLAUeDD0Z4cdHp7wg61GjnEx@ay7LT3O2mopZVUeCaUPQKJGvrooIbkrMYLk8ZgHbMZDquR2Iu7iMarZIr6s1FhfQWfEjIj@eDH9bqtRER82Fc914F@KNTGcn/wFSkHwFu3@Xyn0/ASr7P1F5b/0aaZiDFW8UbVQIolHsV25yrIfkMH0B "Java (JDK) ‚Äì Try It Online")
## Explanations
This code basically divides by zero when the input number is odd or by one when it is even.
### `~n`
The `~` character negates each bit of `n` because `n&1` returns `0` when `n` is even and `1` when it's odd, but we want the opposite: `0` when odd (to make it fail) and `1` when even to return it, so `~` is the easiest way to negate the last bit.
### `~n&1`
This is the part that reduces `n` to either `0` or `1`. `~n&1` is not exactly the same as `~n%2` because, in Java, `%2` keeps the signum of `n`, and since we definitely swap the signum with `~`, we'd always end up with negative number, not matter what `n` is: if `n<0` we'd get negative divided by positive, and if `n>=0`, we'd get positive divided by negative.
We want to divide by `0` or by `1`, nothing else. Only `&1` can guarantee that. No matter what, the operator priority will first evaluate `~n` so no parenthesis are required.
### `/=`
This bit is weird. Why do we do divide and assign, instead of just dividing? Technically, `n/~n&1` will be parsed as `x=n/~n` then `x&1`. This is not the behavior we want: `n/~n` is always equal to `0`. What we want is to have `n/(~n&1)`. It could work well, but the whole answer would be `n->n/(~n&1)`. The `/=` operator is a shortcut to that as it evaluates the right-hand side entirely, so we can get rid of parenthesis, gaining one byte. Assigning is a side effect we can live with.
[Answer]
# MATLAB/Octave, ~~17~~ ~~13~~ 12 bytes
*-4 bytes thanks to [Sisyphus](https://codegolf.stackexchange.com/users/48931/sisyphus)*
```
@(x)x(i^2^x)
```
[Try it online!](https://tio.run/##y08uSSxL/f/fQaNCs0IjM84orkLzf5ptYl6xNRdXSmZxgYa6Z15BaYmVkbomlO9fWgISAPLTNIw00VSZYVdmhqbOEChcUlQJlDKEqXctKsovUsjLL1EoySjKL88DqkhOLEnOUHCFKHDVy00tLk5MT9XkSs1LQTPOHGGeOXkG/gcA "Octave ‚Äì Try It Online")  
Anonymous function. Throws indexing error for odd numbers.
This function returns element from input at index `i^2^x = (-1)^x`, so
* at index `1` for even numbers (which is input itself)
* at index `-1` for odd numbers (which is invalid index since indices in MATLAB start at 1)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 10 bytes
I think this uses an approach that isn't yet represented in the other answers.
*‚Äì1 byte thanks to att!*
```
#+0^I^#^2&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277X1nbIM4zTjnOSO2/S360QkBRZl5JtJJnXkFpia2SjkK2jgKQzC8tgfDTo7NjY3UUqoHChjoKJrUKsf//AwA "Wolfram Language (Mathematica) ‚Äì Try It Online") Here `I` represents the imaginary number *i*. Since the square of every even number is a multiple of 4, `I^#^2` equals 1 when the input is even, and so `0^I^#^2` becomes \$0^1\$ which is a perfectly nice 0 to add to the input. However, since the square of every odd number is one more than a multiple of 4, `I^#^2` equals *i* when the input is odd, and so `0^I^#^2` becomes \$0^i\$ which throws an "Indeterminate expression " error.
## first submission: 11 bytes
```
#+0^(-1)^#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277X1nbIE5D11AzTlntv0t@tEJAUWZeSbSSZ15BaYmtko5Cto4CkMwvLYHw06OzY2N1FKqBwoY6Cia1CrH//wMA "Wolfram Language (Mathematica) ‚Äì Try It Online") Since ‚Äì1 to an even power equals 1, `0^(-1)^#` becomes \$0^1\$ when the input is even, which is a perfectly nice 0 to add to the input; however, since ‚Äì1 to an odd power equals ‚Äì1, `0^(-1)^#` becomes \$0^{-1}\$ (the reciprocal of 0) when the input is odd, which throws an error.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 2 bytes
```
‚ÇÇ·∏≠
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%E2%82%82%E1%B8%AD&inputs=42&header=&footer=)
-1 thanks to Aaron Miller
```
‚ÇÇ  # Is_even(n) (Vyxal has no booleans, only 0 and 1)
 ·∏≠ # Integer division (ordinary division doesn't error on 0)
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~31~~ ~~25~~ ~~14~~ 19 bytes
*-6 bytes thanks to @mazzy*
```
param($n)$n/!($n%2)
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVPUyVPXxFIqxpp/v//3xAA "PowerShell ‚Äì Try It Online")
Calculates the modulo of the input number and `2`, implicitly converts the result to a boolean in order to negate it, then divides the input number by the negation. Inadvertently ditched the spec for a while there, sorry!
[Answer]
# [R](https://www.r-project.org/), 20 bytes
```
n=scan();n+(n%%2&&a)
```
[Try it online!](https://tio.run/##K/r/P8@2ODkxT0PTOk9bI09V1UhNLVHzv8l/AA "R ‚Äì Try It Online")
The `&&` operator is logical AND, evaluating left to right until the result is determined. If `n` is even then `n%%2` is `0`, coerced to `FALSE`, and the `a` part of the expression is therefore not evaluated. We then output `n+0`, ie `n`.
If `n` is odd, then `n%%2` is 1, coerced to `TRUE`, and we need to evaluate the `a` part of the expression to determine the result of `n%%2&&a`. Since `a` is undefined, this produces an error.
This strategy comes out 3 bytes shorter than [Dominic's strategy](https://codegolf.stackexchange.com/a/229061/86301) with `if`.
[Answer]
# [Python 2](https://docs.python.org/2/), 17 bytes
```
lambda n:n/(~n%2)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPKk9foy5P1Ujzf0FRZl6JRpqGkaYmF4xtrKn5HwA "Python 2 ‚Äì Try It Online")
thanks to @hyper-neutrino for -4 bytes
# [Python 3](https://docs.python.org/3/), 24 bytes
```
lambda n:n%2and 1/0 or n
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPKk/VKDEvRcFQ30Ahv0gh739BUWZeiUaahpGmJheMbayp@R8A "Python 3 ‚Äì Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 10 bytes
```
n=>n%2?_:n
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i5P1cg@3irvf3J@XnF@TqpeTn66RpqGiaYmF6qIqabmfwA "JavaScript (Node.js) ‚Äì Try It Online")
Not a very hard answer
[Answer]
# MMIX, 12 bytes (3 instrs)
```
ihateodds   PBEV  $0,0F     // if(n even) goto ret;
            LDVTS $0,$0,6   // privileged instruction
0H          POP   1,0       // ret: return n
```
The `LDVTS` tries to make whatever memory page the input points to RWX in the cache, though not in the page table (if the input is one more than a multiple of 8). This is a privileged instruction for obvious reasons.
[Answer]
# [Python 3](https://docs.python.org/3/), 17 bytes
```
lambda x:[x][x%2]
```
[Try it online!](https://tio.run/##K6gsycjPM/5fYZuZV6KRmVdQWqKhqcmVZqvxPycxNyklUaHCKroiNrpC1Sj2vyZXQRFIWZpGhabmfyMA "Python 3 ‚Äì Try It Online")
It's very simple - construct a list with a single (zeroth) number and take an element of it with index equal to that number modulo 2. Since there is no element 1, it will obviously throw an exception on odd input.
[Answer]
# [PHP](https://php.net), 14.
```
die($argv[0]);
```
There's no need to differentiate odd and even. The criteria say odd numbers can display *any* error, while even ones should be displayed.
Since the criteria allow for ANY error on an even number, and die() displays an error and terminates, the input is fine as an error.
The criteria allow for even numbers to be displayed in any manner, including as an error, so again, the input is fine as an error.
But if die() isn't accepted as an error, and a genuine terminating error's required... **~~27~~ 26 bytes**. Sadly we can't use `die()` here...
```
echo($a=$argv[1])%2?$b:$a;
```
If warnings are acceptable as errors, then in the comments [Matthew Anderson](https://codegolf.stackexchange.com/users/94492/matthew-anderson)'s suggestion to use division by zero also gives us **26 bytes**:
```
echo($a=$argv[1])/!($a%2);
```
[Answer]
# [Factor](https://factorcode.org/), 15 bytes
```
[ 2 / 1 shift ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQnVqUl5qjkJtYkqFQUJRaUlJZUJSZV6JgzcVlpGD8P1rBSEFfwVChOCMzrUQhFsjXU4hVSM7PLcgvTlVIynT4DwA "Factor ‚Äì Try It Online")
*Thanks to @umnikos*
# [Factor](https://factorcode.org/), 19 bytes
```
[ dup 1 + 2 mod / ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQnVqUl5qjkJtYkqFQUJRaUlJZUJSZV6JgzcVlpGD8P1ohpbRAwVBBW8FIITc/RUFfIRYopqcQq5Ccn1uQX5yqkJTp8B8A "Factor ‚Äì Try It Online")
Throws a divide by zero error on odd numbers, while returning even numbers.
## Explanation:
* `dup` Duplicate the input.
**Stack:** (e.g.) `2 2`
* `1 +` Add one.
**Stack:** `2 3`
* `2 mod` Modulo two.
**Stack:** `2 1`
* `/` Divide. (Here is where the error happens for odd input.)
**Stack:** `2`
Here's a slightly longer version that simply asserts the number is not odd:
```
[ dup odd? f assert= ]
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 13 bytes
```
+`[13579]$
99
```
[Try it online!](https://tio.run/##K0otycxL/P9fOyHa0NjU3DJWhcvS8v9/IwA "Retina 0.8.2 ‚Äì Try It Online") Explanation: If the number is odd, simply keeps appending `9`s until Retina eventually runs out of memory, or until TIO kills it, whichever is sooner.
If you want a more direct error, then for 21 bytes:
```
[13579]$
9999999999$*
```
[Try it online!](https://tio.run/##K0otycxL/P8/2tDY1NwyVoXLEg5UtP7/twQA "Retina 0.8.2 ‚Äì Try It Online") Explanation: Tries to append more than a 32-bit integer length of `9`s to the odd input, which throws an OverflowException.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 13 bytes
```
#/Mod[#+1,2]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277X1nfNz8lWlnbUMcoVu1/QFFmXolDerShQSwXjG0c@/8/AA "Wolfram Language (Mathematica) ‚Äì Try It Online")
-1 byte from @att
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 7 bytes ([SBCS](https://github.com/abrudz/SBCS))
Anonymous tacit prefix function
```
‚ä¢√∑1-2|‚ä¢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HXosPbDXWNaoCM/2mP2iY86u171NX8qHfNo94th9YbP2qb@KhvanCQM5AM8fAM/p@mYMSVpmACxMYA "APL (Dyalog Unicode) ‚Äì Try It Online")
`‚ä¢`‚ÄÉthe argument
`√∑`‚ÄÉdivided by
`1-`‚ÄÉone minus
`2|`‚ÄÉthe division remainder when 2 divides
`‚ä¢`‚ÄÉthe argument
Or in other words:$$x\over{1-\Big({x\over2}-\big\lfloor{x\over2}\big\rfloor}\Big)$$
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 9 bytes
```
$_%2&&die
```
[Try it online!](https://tio.run/##K0gtyjH9/18lXtVITS0lM/X/f@N/@QUlmfl5xf91CwA "Perl 5 ‚Äì Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~6~~ 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Throws ~~a `TypeError`~~ an overflow error on odd numbers. ***Still** convinced* there must be a much shorter way ü§î `/v` would work if JavaScript errored on division by 0.
```
*v ¬™√ü
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=KnYgqt8&input=OA)
```
*v ¬™√ü     :Implicit input of integer
*         :Multiply by
 v        :  Divisible by 2?
   ¬™      :Logical OR with
    √ü     :A recursive call
```
[Answer]
# [R](https://www.r-project.org/), ~~25~~ ~~23~~ 22 bytes
*Edit: -2 bytes after looking at [ophact's answer](https://codegolf.stackexchange.com/a/229060/95126), and then -1 byte thanks to Robin Ryder*
```
`if`((n=scan())%%2,,n)
```
[Try it online!](https://tio.run/##K/r/PyEzLUFDI8@2ODkxT0NTU1XVSEcnT/O/8X8A "R ‚Äì Try It Online")
Throws an 'argument is missing' error when `n` is odd and the `if` expression tries to read the missing expression that should be between the two commas.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~28~~ ~~15~~ 14 bytes
-13 thanks to [Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan)  
-1 thanks to [Olivier Gr√©goire](https://codegolf.stackexchange.com/users/16236/olivier-gr%c3%a9goire)
```
f(a){a/=~a&1;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI1GzOlHfti5RzdC69n9mXolCbmJmnoYmVzWXAhAUFAGF0jSUVFOUdNI0TDQ1rbEIm4KEa///S07LSUwv/q9bDgA "C (gcc) ‚Äì Try It Online")
How `~a&1` works is explained in [this solution](https://codegolf.stackexchange.com/a/229111/16236).
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 11 10 bytes
```
1/($1%2-1)
```
[Try it online!](https://tio.run/##SyzP/v/fUF9DxVDVSNdQE8g2AQA "AWK ‚Äì Try It Online")
*Thanks to tail spark rabbit ear for helping drop one char...*
Divides by zero if the number is odd, otherwise the test is truthy and the default action prints the commandline..
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes
```
√à–∏¬ø
```
[Try it online!](https://tio.run/##yy9OTMpM/f//cMeFHYf2//9vBAA "05AB1E ‚Äì Try It Online")
or
```
√à√óF
```
[Try it online!](https://tio.run/##yy9OTMpM/f//cMfh6W7//xsBAA "05AB1E ‚Äì Try It Online")
`√à` checks if the input is even. Returns `1` for even numbers, `0` for odd numbers.
* `–∏` creates a list of this many copies of the input, and `¬ø` calculates the gcd of the list [and throws an error for empty lists](https://github.com/Adriandmen/05AB1E/issues/178)
* `√ó` repeats the input as a string this many times. This results in the input for even inputs and the empty string for odd inputs. `F` is a for loop which crashes if it gets the empty string as an argument. In the end the stack is empty and the input is implicitly printed. `F` could be any of `E`, `F`, `G` and `∆í`.
[Answer]
# [Zsh](https://www.zsh.org/) (math function), 14 bytes
```
((1/1&~$1,$1))
```
[Try it online!](https://tio.run/##FcoxDoAgDAXQnVP8gZg2UbTewxu4ERpcIBFcNHp11Pm9s8SmR/J1y6lgWKAQiFHitRHJKN1jpbfC3DTvqKFU0CXOzdPNBgg@ZlgiKP3G@OIL "Zsh ‚Äì Try It Online")
Unlike in Bash, C and many other languages, in Zsh `&` binds more tightly than `/` by default, allowing us to get division by zero on odd numbers with just `1 / 1 & ~$1`.
(Zsh does have a `C_PRECEDENCES` option which changes arithmetic binding to the traditional order.)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
·∏ÇNXo
```
[Try it online!](https://tio.run/##y0rNyan8///hjia/iPz///@bAQA "Jelly ‚Äì Try It Online")
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
%2NXo
```
[Try it online!](https://tio.run/##y0rNyan8/1/VyC8i/////6YA "Jelly ‚Äì Try It Online")
Look ma, no unicode!
```
·∏ÇNXo  Main Link
·∏Ç     Same thing as %2. 1 if it's odd, 0 if it's even.
 N    Negate. -1 if it's odd, 0 if it's even.
  X   Random number. Errors with -1 as input, returns 0 with 0 as input.
   o  Logical OR. If the input was odd, the program's already errored. Otherwise, it's 0,
      so logical OR gives the right value, which is the input.
```
Unfortunately, since dividing by zero isn't actually an error in Jelly, I cannot use that. Although, it wouldn't save me any bytes: `%2C:@` is the same length.
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 7 bytes
```
:2%?Cn;
```
The input should be put onto the stack using the `-v` command-line argument.
[Try it even!](https://tio.run/##S8sszvj/38pI1d45z/r///@6ZQpGAA)  
[Try it odd!](https://tio.run/##S8sszvj/38pI1d45z/r///@6ZQqGAA)
---
### Explanation:
Initially, the stack contains the input number, \$ n \$.
* `:` duplicates the top of stack: [\$n\$, \$n\$]
* `2` pushes \$2\$ onto stack: [\$n\$, \$n\$, \$2\$]
* `%` pops two values and pushes their modulo: [\$n\$, \$n \% 2\$]
* `?` pops the top value, and if it is \$0\$, the next instruction is skipped: [\$n\$]
If \$n \% 2 \neq 0\$:
* `C` is not a valid instruction, so the program crashes.
If \$n \% 2 = 0\$:
* `n` pops off the top value (\$n\$) and prints it: []
* `;` terminates the program.
[Answer]
# R, ~~20~~ 19 bytes
```
(x=scan())[[!x%%2]]
```
[Try it online!](https://tio.run/##K/r/X6PCtjg5MU9DUzM6WrFCVdUoNva/Mdd/AA "R ‚Äì Try It Online")
# R 4.1, ~~15~~ 14 bytes
```
\(x)x[[!x%%2]]
```
Takes advantage of the fact that an R numeric is automatically a vector.
-1 byte by using a different indexing error due to Dominic van Essen.
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 44 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input][S N
S _Duplicate_input][S S S T S N
_Push_2][T  S T T   _Modulo][N
T   S N
_If_0_Jump_to_Label_EVEN][N
S N
S N
_Jump_to_nonexistent_Label][N
S S N
_Create_Label_Even][T   N
S T _Print_as_integer]
```
Letters S (space), T (tab), and N (new-line) added as highlighting only.
[...\_some\_action] added as explanation only.
[**Try it online**](https://tio.run/##K8/ILEktLkhMTv3/X0FBgQsIObk4QQDIAgIgxanACRRS4ALJAQmgAFDN///mAA) (with raw spaces, tabs and new-lines only).
**Explanation in pseudo-code:**
```
Integer input = STDIN as integer
Integer temp = input modulo-2
If (temp == 0):
  Go to label EVEN
Go to nonexistent label (causing an error)
Label EVEN:
  Print input as integer
  (also shows an error: no exit defined; could be prevented by adding three trailing newlines)
```
]