CJCoding With Joseph

Null Reference Exception

A variable text starts as null. Read an integer cmd; if cmd == 1, set text = "hello". Then print Length: <text.Length>. If text is still null, accessing .Length throws a NullReferenceException; catch it and print Text was null. Use top-level statements with try/catch.

Input 1 prints: Length: 5
Input 0 prints: Text was null

Expected Output:

Length: 5
Topics:
Exceptions
๐Ÿ“ฅ Auto-Input:
1\n
This input is automatically fed to your program's stdin
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.