```python
def code_valid(code: str, length: int) -> bool:
    """Check if a code is valid based on length and character constraints."""
    if length <= 0:
        raise ValueError("Length must be greater than zero")
    
    if len(code) != length:
        return False
    
    if not code:
        return False
    
    for char in code:
        if not (char.isupper() or char.isdigit()):
            return False
            
    return True
```