Project

General

Profile

Feature #12482

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

Currently: 

 ~~~ruby 
 ~~~ 
 ArgumentError.new(nil)    =>    #<ArgumentError: ArgumentError> 
 ArgumentError.new(nil).to_s => "ArgumentError" 
 ArgumentError.new(nil).inspect => "#<ArgumentError: ArgumentError>" 

 ~~~ 

 I want to suggest to change this to "ArgumentError(nil)" instead. 

 Rational: 

 For testing arguments, I frequently use: 

 ~~~ruby 
 ~~~ 
 raise ArgumentError.new(arg) unless ExpectedClass === arg 
 

 ~~~ 

 However when arg is nil, this raises "ArgumentError" while raising "ArgumentError(nil)" would be much nicer. 

 This would differentiate between `ArgumentError.new()` ArgumentError.new() and `ArgumentError.new(nil)` 

 ArgumentError.new(nil)  

 Suggested changes 

 It I't looks like `ArgumentError#initialize` ArgumentError#initialize inherits Exception#initialize 

 I'd like to suggest to differentiate between Exception.new() and Exception.new(nil) 

 ~~~ruby ~~~ 
 def Exception.new(msg = :__Exception_msg_arg_undefined___) 
   case arg 
   when :__Exception_msg_arg_undefined___ 
     # msg = "ClassName" 
   when nil 
     # msg = "ClassName(nil)"  
   end 
 ~~~ 

 Impact 

 I believe this should not break existing code as no code should rely on the string returned. 












Back