studyzy/imewlconverter · error · Exception
找不到拼音
Error message
找不到拼音
What it means
ZhuyinHelper.GetZhuyin(string) converts a pinyin syllable into Bopomofo (注音). Identical guard pattern to Chaoyin (error [0]): it throws this bare Exception ONLY for null/empty pinyin input; it returns null (not throws) for a valid-but-unmapped pinyin. So this throw means the caller passed no pinyin, not an unknown one.
Source
Thrown at src/ImeWlConverter.Core/Helpers/ZhuyinHelper.cs:70
var arr = line.Split('\t');
var zhuyinCode = arr[0];
var pinyin = arr[1];
if (!pinyinDic.ContainsKey(zhuyinCode))
pinyinDic.Add(zhuyinCode, pinyin);
else
Debug.WriteLine(pinyin + " mapping more than 1 pinyin");
}
}
return pinyinDic;
}
}
public static string? GetZhuyin(string pinyin)
{
if (string.IsNullOrEmpty(pinyin)) throw new Exception("找不到拼音");
var yindiao = 10;
if (regex.IsMatch(pinyin))
{
yindiao = Convert.ToInt32(pinyin[pinyin.Length - 1].ToString());
pinyin = pinyin.Substring(0, pinyin.Length - 1);
}
if (!ZhuyinDic.ContainsKey(pinyin))
{
Debug.WriteLine("Can not find zhuyin by pinyin=" + pinyin);
return null;
}
var zy = ZhuyinDic[pinyin] + GetYindiaoZhuyin(yindiao);
Debug.WriteLine("Pinyin:" + pinyin + ",Zhuyin:" + zy);
return zy;
}
View on GitHub (pinned to 16744a12ed)
Solutions
- Filter empty/whitespace strings out of the pinyin list before calling zhuyin generation.
- Guard each pinyin with string.IsNullOrEmpty(p) and skip when blank.
- Fix upstream pinyin resolution so empty pinyins never reach the generator.
Example fix
// before var zy = ZhuyinHelper.GetZhuyin(p); // after if (string.IsNullOrEmpty(p)) continue; var zy = ZhuyinHelper.GetZhuyin(p);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(pinyin)) continue; var zy = ZhuyinHelper.GetZhuyin(pinyin);
Try / catch
try { var zy = ZhuyinHelper.GetZhuyin(p); }
catch (Exception ex) when (ex.Message == "找不到拼音") { /* skip empty pinyin */ } Prevention
- Never pass an empty/null pinyin to a tone or script conversion helper.
- Filter empty strings out of pinyin lists before zhuyin generation.
- Resolve pinyin upstream so blanks never reach the generator.
When it happens
Trigger: Calling ZhuyinHelper.GetZhuyin(null) or GetZhuyin(""); or indirectly via GetZhuyin(IList<string>) (line 92) when the list contains an empty pinyin string.
Common situations: Zhuyin code generation on a word whose pinyin could not be resolved upstream, so an empty pinyin was passed in; an importer emitted blank pinyin codes that reach the zhuyin generator.
Related errors
AI-assisted analysis of studyzy/imewlconverter@16744a12ed (2026-08-13).
Data as JSON: /api/errors/eacde7cc841e0613.
Report an issue: GitHub.