{"record":{"id":"5a35c19d861ae614","repo":"TheAlgorithms/Java","slug":"unknown-word","errorCode":"UNKNOWN_WORD","errorMessage":"Invalid Input. Unknown Word: {word}","messagePattern":"Invalid Input\\. Unknown Word: (.+?)","errorType":"exception","errorClass":"WordsToNumberException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/conversions/WordsToNumber.java","lineNumber":261,"sourceCode":"                currentChunk = handleNumber(chunks, currentChunk, word, number);\n                continue;\n            }\n\n            switch (word) {\n                case \"point\" -> {\n                    handlePoint(chunks, currentChunk, wordDeque);\n                    currentChunk = BigDecimal.ZERO;\n                    continue;\n                }\n                case \"negative\" -> {\n                    handleNegative(isNegative);\n                }\n                default -> {\n\n                }\n            }\n\n            throw new WordsToNumberException(WordsToNumberException.ErrorType.UNKNOWN_WORD, word);\n        }\n\n        if (currentChunk.compareTo(BigDecimal.ZERO) != 0) {\n            chunks.add(currentChunk);\n        }\n\n        BigDecimal completeNumber = combineChunks(chunks);\n        return isNegative ? completeNumber.multiply(BigDecimal.valueOf(-1))\n                :\n                    completeNumber;\n                }\n\n                private static boolean isAdditionSafe(BigDecimal currentChunk, BigDecimal number) {\n                    int chunkDigitCount = currentChunk.toString().length();\n                    int numberDigitCount = number.toString().length();\n                    return chunkDigitCount > numberDigitCount;\n                }\n","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/conversions/WordsToNumber.java#L243-L279","documentation":"Thrown at the end of the main parsing loop when a word does not match any known category: not 'and', not 'hundred', not a power of ten, not a NumberWord, not 'point', not 'negative'. The default branch of the second switch falls through to this throw. The offending word is interpolated into the message.","triggerScenarios":"convert('five baz'), convert('hello world'), convert('one hunderd') (typo), convert('twenty twohundred') (no space), convert('3.14') (numeric digits not words).","commonSituations":"Typos; non-English words; numeric digits instead of spelled-out words; concatenated words without delimiters; unsupported scale words like 'crore' or 'lakh'.","solutions":["Ensure all words are valid English number words from the supported vocabulary (zero-nineteen, twenty-ninety by tens, hundred, thousand, million, billion, trillion, point, negative, and).","Spell-check and delimiter-check the input.","If supporting other scales, pre-map them to the canonical vocabulary."],"exampleFix":"// before\nWordsToNumber.convert('one hunderd');\n// after\nWordsToNumber.convert('one hundred'); // 100","handlingStrategy":"validation","validationCode":"static final Set<String> VOCAB = Set.of(\n    \"zero\",\"one\",\"two\",\"three\",\"four\",\"five\",\"six\",\"seven\",\"eight\",\"nine\",\"ten\",\"eleven\",\"twelve\",\"thirteen\",\"fourteen\",\"fifteen\",\"sixteen\",\"seventeen\",\"eighteen\",\"nineteen\",\"twenty\",\"thirty\",\"forty\",\"fifty\",\"sixty\",\"seventy\",\"eighty\",\"ninety\",\"hundred\",\"thousand\",\"million\",\"billion\",\"trillion\",\"point\",\"negative\",\"and\");\nstatic boolean allWordsKnown(String s) {\n    for (String w : s.trim().toLowerCase(Locale.ROOT).split(\"[ ,-]+\")) {\n        if (!VOCAB.contains(w)) return false;\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { WordsToNumber.convert(input); } catch (WordsToNumberException e) {\n    if (e.errorType == ErrorType.UNKNOWN_WORD) throw new ApiException(400, \"Unrecognized word in input: \" + e.getMessage());\n    throw e;\n}","preventionTips":["Validate every word against the supported vocabulary before calling convert.","Spell-check and delimiter-check input.","Map non-English or locale-specific scale words to canonical forms upstream."],"tags":["java","words-to-number","unknown-word","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}