44using System . Reflection ;
55using System . Runtime . CompilerServices ;
66using System . Runtime . InteropServices ;
7+ using System . Runtime . Serialization ;
78using UnityEngine . InputSystem . LowLevel ;
89using UnityEngine . InputSystem . Utilities ;
910
@@ -1175,7 +1176,7 @@ private static void ThrowIfControlItemIsDuplicate(ref ControlItem controlItem,
11751176 foreach ( var existing in controlLayouts )
11761177 if ( string . Compare ( name , existing . name , StringComparison . OrdinalIgnoreCase ) == 0 &&
11771178 existing . variants == controlItem . variants )
1178- throw new Exception ( $ "Duplicate control '{ name } ' in layout '{ layoutName } '") ;
1179+ throw new InvalidOperationException ( $ "Duplicate control '{ name } ' in layout '{ layoutName } '") ;
11791180 }
11801181
11811182 internal static void ParseHeaderFieldsFromJson ( string json , out InternedString name ,
@@ -1246,7 +1247,7 @@ public InputControlLayout ToLayout()
12461247 }
12471248 else if ( ! typeof ( InputControl ) . IsAssignableFrom ( type ) )
12481249 {
1249- throw new Exception ( $ "'{ this . type } ' used by layout '{ name } ' is not an InputControl") ;
1250+ throw new InvalidOperationException ( $ "'{ this . type } ' used by layout '{ name } ' is not an InputControl") ;
12501251 }
12511252 }
12521253 else if ( string . IsNullOrEmpty ( extend ) )
@@ -1280,7 +1281,7 @@ public InputControlLayout ToLayout()
12801281 else if ( beforeRenderLowerCase == "update" )
12811282 layout . m_UpdateBeforeRender = true ;
12821283 else
1283- throw new Exception ( $ "Invalid beforeRender setting '{ beforeRender } '") ;
1284+ throw new InvalidOperationException ( $ "Invalid beforeRender setting '{ beforeRender } '") ;
12841285 }
12851286
12861287 // Add common usages.
@@ -1294,7 +1295,7 @@ public InputControlLayout ToLayout()
12941295 foreach ( var control in controls )
12951296 {
12961297 if ( string . IsNullOrEmpty ( control . name ) )
1297- throw new Exception ( $ "Control with no name in layout '{ name } ") ;
1298+ throw new InvalidOperationException ( $ "Control with no name in layout '{ name } ") ;
12981299 var controlLayout = control . ToLayout ( ) ;
12991300 ThrowIfControlItemIsDuplicate ( ref controlLayout , controlLayouts , layout . name ) ;
13001301 controlLayouts . Add ( controlLayout ) ;
@@ -1561,9 +1562,9 @@ private InputControlLayout TryLoadLayoutInternal(InternedString name)
15611562 {
15621563 var layoutObject = builder . method . Invoke ( builder . instance , null ) ;
15631564 if ( layoutObject == null )
1564- throw new Exception ( $ "Layout builder '{ name } ' returned null when invoked") ;
1565+ throw new InvalidOperationException ( $ "Layout builder '{ name } ' returned null when invoked") ;
15651566 if ( ! ( layoutObject is InputControlLayout layout ) )
1566- throw new Exception (
1567+ throw new InvalidOperationException (
15671568 $ "Layout builder '{ name } ' returned '{ layoutObject } ' which is not an InputControlLayout") ;
15681569 return layout ;
15691570 }
@@ -1712,14 +1713,35 @@ internal struct BuilderInfo
17121713 public object instance ;
17131714 }
17141715
1715- internal class LayoutNotFoundException : Exception
1716+ public class LayoutNotFoundException : Exception
17161717 {
17171718 public string layout { get ; }
1718- public LayoutNotFoundException ( string name , string message = null )
1719- : base ( message ?? $ "Cannot find control layout '{ name } '")
1719+
1720+ public LayoutNotFoundException ( )
1721+ {
1722+ }
1723+
1724+ public LayoutNotFoundException ( string name , string message )
1725+ : base ( message )
1726+ {
1727+ layout = name ;
1728+ }
1729+
1730+ public LayoutNotFoundException ( string name )
1731+ : base ( $ "Cannot find control layout '{ name } '")
17201732 {
17211733 layout = name ;
17221734 }
1735+
1736+ public LayoutNotFoundException ( string message , Exception innerException ) :
1737+ base ( message , innerException )
1738+ {
1739+ }
1740+
1741+ protected LayoutNotFoundException ( SerializationInfo info ,
1742+ StreamingContext context ) : base ( info , context )
1743+ {
1744+ }
17231745 }
17241746
17251747 // Constructs InputControlLayout instances and caches them.
0 commit comments